Last active
December 28, 2018 13:57
-
-
Save JanKoppe/a22f59f21b36b1a21e564021c0d3a28f to your computer and use it in GitHub Desktop.
Chaos-West Fahrplan quick overview/clock
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import time | |
import icalendar | |
import datetime | |
import pytz | |
from colored import fg, bg, attr | |
def loopme(): | |
r = requests.get('https://fahrplan.chaos-west.de/35c3chaoswest/schedule/export/schedule.ics') | |
cal = icalendar.Calendar.from_ical(r.text) | |
events = [] | |
tz = pytz.timezone('Europe/Berlin') | |
now = datetime.datetime.now(tz=tz) | |
for i, component in enumerate(cal.walk('vevent')): | |
start = component.get('dtstart').dt.astimezone(tz) | |
if start > now: | |
prev = cal.walk('vevent')[i-2] | |
curr = cal.walk('vevent')[i-1] | |
next = cal.walk('vevent')[i] | |
if (next.get('dtstart').dt.astimezone(tz)-now).seconds/60 < 15: | |
blinky = attr('blink') + attr('bold') | |
color = fg('light_red') | |
else: | |
blinky = "" | |
color = fg('light_yellow') | |
print("%sprev[%d]: %s-%s '%.40s'%s" % (fg('dark_gray'), i-2, prev.get('dtstart').dt.astimezone(tz).strftime('%H:%M'), prev.get('dtend').dt.astimezone(tz).strftime('%H:%M'), prev.get('summary'), attr('reset'))) | |
print("%scurr[%d]: %s-%s '%.40s'%s" % (fg('light_green'), i-1, curr.get('dtstart').dt.astimezone(tz).strftime('%H:%M'), curr.get('dtend').dt.astimezone(tz).strftime('%H:%M'), curr.get('summary'), attr('reset'))) | |
print("%s%snext[%d]: %s-%s '%.40s'%s" % (color, blinky, i, next.get('dtstart').dt.astimezone(tz).strftime('%H:%M'), next.get('dtend').dt.astimezone(tz).strftime('%H:%M'), next.get('summary'), attr('reset'))) | |
break | |
while True: | |
loopme() | |
time.sleep(60) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment