try to make it look like python
This commit is contained in:
parent
35fe345288
commit
4a331c18f6
1
requirements.txt
Normal file
1
requirements.txt
Normal file
|
@ -0,0 +1 @@
|
|||
icalendar
|
|
@ -1,14 +1,15 @@
|
|||
#!/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:
|
||||
|
@ -17,6 +18,7 @@ def vevent_to_event(event, rrstart=None):
|
|||
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('</table>')
|
||||
|
||||
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()
|
||||
|
|
|
@ -1,25 +1,27 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
from glob import glob
|
||||
import icalendar
|
||||
|
||||
import pytz
|
||||
import icalendar
|
||||
|
||||
|
||||
cals = []
|
||||
merged = icalendar.Calendar()
|
||||
merged.add('prodid', '-//CCCB Calendar Generator//berlin.ccc.de//')
|
||||
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())
|
||||
|
||||
|
|
Loading…
Reference in a new issue