diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..744b7a9 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +icalendar diff --git a/tools/gen_upcoming.py b/tools/gen_upcoming.py index d611668..ff05fe7 100755 --- a/tools/gen_upcoming.py +++ b/tools/gen_upcoming.py @@ -1,22 +1,24 @@ #!/usr/bin/env python3 import sys -from datetime import datetime, timedelta -from dateutil.parser import parse -from dateutil.rrule import rruleset, rrulestr -import icalendar -import locale import logging - +import locale from pprint import pprint +from dateutil.parser import parse +from datetime import datetime, timedelta +from dateutil.rrule import rruleset, rrulestr + +import icalendar + def vevent_to_event(event, rrstart=None): if rrstart == None: begin = parse(event['DTSTART'].to_ical()) else: - begin = rrstart + begin = rrstart return { "name": event['SUMMARY'].to_ical(), "url": event['URL'].to_ical(), "begin": begin } + def parse_single_event(event, start, end): logging.info("Processing single event %s" % event['SUMMARY'].to_ical().decode('utf-8')) dtstart = parse(event['DTSTART'].to_ical()) @@ -25,6 +27,7 @@ def parse_single_event(event, start, end): else: return None + def parse_recurring_event(event, start, end): logging.info("Processing recurring event %s" % event['SUMMARY'].to_ical().decode('utf-8')) dtstart = parse(event['DTSTART'].to_ical()) @@ -71,7 +74,8 @@ def format_events(events): % (dateStr, event['url'].decode('utf-8'), event['name'].decode('utf-8'))) print('') -def main(): + +if __name__ == "__main__": if len(sys.argv) < 3: print("Usage: %s calendar max_days max_items" % sys.argv[0]) sys.exit(-1) @@ -84,5 +88,3 @@ def main(): events=find_events(calendar, datetime.now(), datetime.now() + timedelta(days=max_days), max_items) format_events(events) -if __name__ == "__main__": - main() diff --git a/tools/merge_cals.py b/tools/merge_cals.py index 463cd80..0df4949 100755 --- a/tools/merge_cals.py +++ b/tools/merge_cals.py @@ -1,25 +1,27 @@ #!/usr/bin/env python3 from glob import glob -import icalendar + import pytz +import icalendar -cals=[] -merged=icalendar.Calendar() + +cals = [] +merged = icalendar.Calendar() merged.add('prodid', '-//CCCB Calendar Generator//berlin.ccc.de//') -merged.add('version', '2.0') +merged.add('version', '2.0') -for icsfilestr in glob("public/*/**/*.ics", recursive=True): +for icsfilestr in glob('public/*/**/*.ics', recursive=True): with open(icsfilestr, 'r') as icsfile: - print("Importing", icsfilestr) + print('Importing', icsfilestr) cals.append(icalendar.Calendar.from_ical(icsfile.read())) for cal in cals: for e in cal.subcomponents: merged.add_component(e) -outfile="static/all.ics" +outfile = 'static/all.ics' with open(outfile, 'wb') as f: - print(f"writing to {outfile}...") + print(f'writing to {outfile}...') f.write(merged.to_ical()) - +