-
Notifications
You must be signed in to change notification settings - Fork 0
/
update-calendar.py
94 lines (75 loc) · 3.04 KB
/
update-calendar.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
"""
Updates the iCal calendar file in the root directory. Just run it in the top level dir in its stock
configuration:
python scripts/update-calendar.py
"""
import json
from datetime import datetime, timedelta
from icalendar import Calendar, Event
import pytz
def parse_date(date_str):
if isinstance(date_str, str):
return datetime.strptime(date_str, "%Y-%m-%d").date()
elif isinstance(date_str, dict) and 'estimated' in date_str:
return datetime.strptime(date_str['estimated'], "%Y-%m-%d").date()
elif isinstance(date_str, dict) and 'when' in date_str:
return datetime.strptime(date_str['when'], "%Y-%m-%d").date()
return None
def create_event(name, start_date, end_date=None, description=""):
event = Event()
event.add('summary', name)
event.add('dtstart', start_date)
if end_date:
event.add('dtend', end_date)
else:
event.add('dtend', start_date + timedelta(days=1)) # Make it an all-day event
description += "\n\nFull Calendar: https://github.com/paritytech/release-registry?tab=readme-ov-file#calendar"
event.add('description', description)
return event
def generate_ical(data):
cal = Calendar()
cal.add('prodid', '-//Polkadot SDK Release Calendar//EN')
cal.add('version', '2.0')
sdk_data = data['Polkadot SDK']
for release in sdk_data['releases']:
release_name = release['name']
release_state = release['state']
# Release cutoff event
cutoff_date = parse_date(release['cutoff'])
if cutoff_date:
event = create_event(f"{release_name} Cutoff", cutoff_date, description=f"Cutoff for {release_name} ({release_state})")
cal.add_component(event)
# Release publish event
publish_date = parse_date(release['publish'].get('when') or release['publish'].get('estimated'))
if publish_date:
event = create_event(f"{release_name} Release", publish_date, description=f"Release of {release_name} ({release_state})")
cal.add_component(event)
# End of life event
eol_date = parse_date(release.get('endOfLife'))
if eol_date:
event = create_event(f"{release_name} End of Life", eol_date, description=f"End of Life for {release_name}")
cal.add_component(event)
# Patch events
for patch in release.get('patches', []):
patch_name = patch['name']
patch_state = patch['state']
# Patch cutoff event
patch_cutoff_date = parse_date(patch['cutoff'])
if patch_cutoff_date:
event = create_event(f"{patch_name} Cutoff", patch_cutoff_date, description=f"Cutoff for {patch_name} ({patch_state})")
cal.add_component(event)
# Patch publish event
patch_publish_date = parse_date(patch['publish'].get('when') or patch['publish'].get('estimated'))
if patch_publish_date:
event = create_event(f"{patch_name} Release", patch_publish_date, description=f"Release of {patch_name} ({patch_state})")
cal.add_component(event)
return cal.to_ical()
# Load JSON data
with open('releases-v1.json', 'r') as f:
data = json.load(f)
# Generate iCal
ical_data = generate_ical(data)
# Write to file
with open('releases-v1.ics', 'wb') as f:
f.write(ical_data)
print("iCal file 'releases-v1.ics' has been generated.")