-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoutput-events.py
36 lines (30 loc) · 973 Bytes
/
output-events.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import os
import yaml
from datetime import date
from icalendar import Calendar, Event
with open("data/events.yaml", 'r') as stream:
try:
data = yaml.safe_load(stream)
except yaml.YAMLError as exc:
print(exc)
cal = Calendar()
cal.add('prodid', '-//investorwag.com//Scrappy ASX Calendar//EN')
cal.add('version', '2.0')
cal.add('calscale', 'GREGORIAN')
cal.add('method', 'PUBLISH')
uid = 0
for json_event in data['events']:
event = Event()
event['uid'] = 'scrappy-asx-calendar-%s' % (uid)
event['summary'] = json_event['summary']
event['description'] = json_event['description']
event['transp'] = 'TRANSPARENT' # not seen as busy event
date_string = json_event['date'].strftime('%Y%m%d')
event['dtstart'] = date_string
cal.add_component(event)
uid += 1
filename = "output/scrappy-asx-calendar.ics"
os.makedirs(os.path.dirname(filename), exist_ok=True)
f = open(filename, 'wb')
f.write(cal.to_ical())
f.close()