Option override PRODID at import time ? #278
Replies: 2 comments
-
Hi @jasonehines |
Beta Was this translation helpful? Give feedback.
-
Hi @jasonehines! Happened to scroll by, hopefully you aren't still having this problem. For anyone else having this problem, hope this snippet helps. It adds the missing PRODID on-the-fly in memory, without creating temporary files or modifying the original. def cal_from_file(filename: str, prodid: str = 'PRODID:-//placeholder//text//EN\n') -> Calendar:
buf = []
with open(filename, 'r') as f:
i = 0
vcal = -1
missing_prodid = True
for line in f:
buf.append(line)
if line == "BEGIN:VCALENDAR\n":
vcal = i
missing_prodid = True
elif line == "END:VCALENDAR\n":
if missing_prodid:
#print(f'VCALENDAR without PRODID on line {vcal} in {filename}.')
buf[vcal] = buf[vcal] + prodid
vcal = -2
elif vcal != -1 and missing_prodid and line.startswith("PRODID:"):
missing_prodid = False
i += 1
if vcal == -1:
raise TypeError(f'{filename} is not an ics file') # FIXME
elif vcal >= 0 and missing_prodid:
#print(f'VCALENDAR without PRODID nor end on line {vcal} in {filename}.')
buf[vcal] = buf[vcal] + prodid
return Calendar(''.join(buf)) It should handle multiple VCALENDARs in a single file as long as they each have an END line - the latter adder was an afterthought after I came across ics files containing a single BEGIN with no END. It's not pretty, predating my usage of enumerate() and all, but it gets the job done and is way faster than using try-except (and thus having ics-py parse the file twice). |
Beta Was this translation helpful? Give feedback.
-
It seems that Apple's icloud public calendar doesn't have a PRODID. Here's the header from mine
Is there someway to override the PRODID when importing?
Beta Was this translation helpful? Give feedback.
All reactions