Skip to content

Instantly share code, notes, and snippets.

@JanKoppe

JanKoppe/clock.py

Last active Dec 28, 2018
Embed
What would you like to do?
Chaos-West Fahrplan quick overview/clock
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
You can’t perform that action at this time.