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 convert an ics to md, if (many) vevents don't have category #317

Closed
Tracked by #443
DoctorSubtilis opened this issue Dec 30, 2020 · 1 comment
Closed
Tracked by #443

Comments

@DoctorSubtilis
Copy link

DoctorSubtilis commented Dec 30, 2020

I get an error message when I try to convert an ics calendar, whose (many) vevents are without category.
The message is

  File "/usr/local/lib/python3.8/dist-packages/ics/component.py", line 54, in _populate
  raise ValueError(
 ValueError: A VEVENT must have at most one CATEGORIES

I use a Python 3 script to convert ics to md:

from ics import Calendar

md_template = """
### {start}
*{name}*: {desc}""" 

with open("diario.ics") as f:
   cal = Calendar(f.read())

print("## Diario")
for e in sorted(cal.events):
print(md_template.format(start=e.begin.strftime("%Y-%m-%e"), name=e.name, 
                         desc=e.description))

There is a workaround to avoid this behavior, without add manually a category to every vevent (quite boring)?

@jacadzaca
Copy link
Collaborator

jacadzaca commented Sep 5, 2022

I presume you wanted to achieve something like this...

from icalendar import Calendar

md_template = """
### {start}
*{name}*: {desc}"""

with open("sample.ics") as f:
   cal = Calendar.from_ical(f.read())

print("## Diario")
for event in cal.walk('vevent'):
    print(md_template.format(start=event.decoded('dtstart').strftime("%Y-%m-%e"),
                             name=event.get('summary'),
                             desc=event.get('description')))

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

2 participants