Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to modify a column of iCal in Python #342

Closed
Tracked by #443
nuhkoca opened this issue Dec 24, 2021 · 5 comments
Closed
Tracked by #443

How to modify a column of iCal in Python #342

nuhkoca opened this issue Dec 24, 2021 · 5 comments

Comments

@nuhkoca
Copy link

nuhkoca commented Dec 24, 2021

Hello,

I already asked this question on SO abut I think it is quite intensive because I haven't got an answer yet so I thought it'd be better to raise here. Would appreciate if you can solve my problem.

I am pulling absences from an ics file. The summary column includes employee name like so:

[Absences] John Doe (half day)

I have a regex pattern below that helps extract employee name from such a complex string given:

name_extractor = re.compile("(?:\[.*\]\s*)?([^\(]+)(?<![\ ])", re.VERBOSE)

Having said all those, I'd like to have a modified summary column in for loop instead. However, I deadlock in how to manipulate the summary column only but to keep others as they are just before proceeding the next lines. I tried below but I am only having the modified summary column instead of an entire vevent object inside for loop.

cal = filter(
    lambda c: c.name == 'VEVENT',
    icalendar.Calendar.from_ical(ics_string).walk()
)
    
cal = map(
    lambda c: name_extractor.search(c.get('summary')).groups()[0],
    cal
)

for vevent in cal:
    summary = str(vevent.get('summary')) # -> This is still unformatted like above [Absences] John Doe (half day)
 ...
rest of code
@angatha
Copy link
Collaborator

angatha commented Nov 1, 2022

@nuhkoca is this still relevant? Does the code at least run for you without an axception? Since vevent has type str, I expect the get call to fail. But that is not the original problem, right?

@niccokunzmann
Copy link
Member

Can you give is the link to stackoverflow?

@angatha
Copy link
Collaborator

angatha commented Nov 1, 2022

Ah SO ist stackoverflow. Thanks @niccokunzmann

@nuhkoca
Copy link
Author

nuhkoca commented Nov 1, 2022

Hey @niccokunzmann and @angatha sorry I quit working on it quite a long time ago so I don't remember details 😕 But the SO link is: https://stackoverflow.com/questions/70468922/how-to-modify-a-column-of-ical-in-python

@niccokunzmann
Copy link
Member

I close this issue as it is not applicable to you and an answer can be posted on SO. Feel free to re-open it, if you find it useful.
Thanks @nuhkoca @angatha!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants