Skip to content

Commit

Permalink
fix 3 year calendar
Browse files Browse the repository at this point in the history
  • Loading branch information
ezwang committed Mar 17, 2019
1 parent 3b73a63 commit 1cd0a7d
Showing 1 changed file with 24 additions and 20 deletions.
44 changes: 24 additions & 20 deletions penn/calendar3year.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import datetime


BASE_URL = "https://www.google.com/calendar/ical/[email protected]/public/basic.ics"
BASE_URL = "https://www.stanza.co/api/schedules/almanacacademiccalendar/"


class Calendar(object):
Expand All @@ -20,25 +20,29 @@ def pull_3year(self):
- End date 'end'
"""
events = []
r = requests.get(BASE_URL).text
lines = r.split("\r\n")
d = {}
for line in lines:
if line == "BEGIN:VEVENT":
d = {}
elif line[:7] == "DTSTART":
raw_date = line.split(":")[1]
start_date = datetime.datetime.strptime(raw_date, '%Y%m%d').date()
d['start'] = start_date.strftime('%Y-%m-%d')
elif line[:5] == "DTEND":
raw_date = line.split(":")[1]
end_date = datetime.datetime.strptime(raw_date, '%Y%m%d').date()
d['end'] = end_date.strftime('%Y-%m-%d')
elif line[:7] == "SUMMARY":
name = line.split(":")[1]
d['name'] = str(name).strip()
elif line == "END:VEVENT":
events.append(d)
for term in ["fall", "summer", "spring"]:
url = "{}{}{}term.ics".format(BASE_URL, datetime.datetime.now().year, term)
resp = requests.get(url)
resp.raise_for_status()
r = resp.text
lines = r.split("\n")
d = {}
for line in lines:
if line == "BEGIN:VEVENT":
d = {}
elif line.startswith("DTSTART"):
raw_date = line.split(":")[1]
start_date = datetime.datetime.strptime(raw_date, '%Y%m%d').date()
d['start'] = start_date.strftime('%Y-%m-%d')
elif line.startswith("DTEND"):
raw_date = line.split(":")[1]
end_date = datetime.datetime.strptime(raw_date, '%Y%m%d').date()
d['end'] = end_date.strftime('%Y-%m-%d')
elif line.startswith("SUMMARY"):
name = line.split(":")[1]
d['name'] = str(name).strip()
elif line == "END:VEVENT":
events.append(d)

events.sort(key=lambda d: d['start'])
return events

0 comments on commit 1cd0a7d

Please sign in to comment.