Skip to content

Instantly share code, notes, and snippets.



Last active Dec 28, 2018
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('')
cal = icalendar.Calendar.from_ical(r.text)
events = []
tz = pytz.timezone('Europe/Berlin')
now =
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')
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')))
while True:
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.