From 4a331c18f6fd6d53104c88512c8f93952846d616 Mon Sep 17 00:00:00 2001 From: "Ricardo (XenGi) Band" Date: Wed, 15 Aug 2018 00:49:06 +0200 Subject: [PATCH] try to make it look like python --- requirements.txt | 1 + tools/gen_upcoming.py | 22 ++++++++++++---------- tools/merge_cals.py | 20 +++++++++++--------- 3 files changed, 24 insertions(+), 19 deletions(-) create mode 100644 requirements.txt 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()) - +