diff options
Diffstat (limited to 'epaper/main.py')
-rw-r--r-- | epaper/main.py | 50 |
1 files changed, 29 insertions, 21 deletions
diff --git a/epaper/main.py b/epaper/main.py index b25c821..6e97544 100644 --- a/epaper/main.py +++ b/epaper/main.py @@ -3,29 +3,37 @@ import epd2in13 import time +import requests +from datetime import date +from datetime import datetime from PIL import Image,ImageDraw,ImageFont -import traceback font_size = 14 -try: - epd = epd2in13.EPD() - epd.init(epd.FULL_UPDATE) - epd.Clear(0xFF) - - # Drawing on the image - image = Image.new('1', (epd2in13.EPD_HEIGHT, epd2in13.EPD_WIDTH), 255) # 255: clear the frame - - draw = ImageDraw.Draw(image) - font = ImageFont.truetype('/usr/share/fonts/truetype/wqy/wqy-microhei.ttc', font_size) - draw.text((0, 0), 'Guten Tag!', font=font, fill=0) - draw.text((0, font_size + 2), 'Marvin ist toll!', font=font, fill=0) - epd.display(epd.getbuffer(image)) - # time.sleep(10) - # epd.Clear(0xFF) - epd.sleep() - -except: - print('traceback.format_exc():\n%s',traceback.format_exc()) - exit() +epd = epd2in13.EPD() +epd.init(epd.FULL_UPDATE) +epd.Clear(0xFF) +image = Image.new('1', (epd2in13.EPD_HEIGHT, epd2in13.EPD_WIDTH), 255) # 255: clear the frame +draw = ImageDraw.Draw(image) +font = ImageFont.truetype('/usr/share/fonts/truetype/wqy/wqy-microhei.ttc', font_size) + +resp = requests.get('http://data.c3voc.de/36C3/everything.schedule.json') +days = resp.json()['schedule']['conference']['days'] +conferences = [] +for day in days: + for room in day['rooms']: + for conference in day['rooms'][room]: + conf_date = time.mktime(datetime.strptime(conference['date'], '%Y-%m-%dT%H:%M:%S%z').timetuple()) + if conf_date - time.time() > 2 * 60 * 60: + conferences.append(conference) + +sorted_list = sorted(conferences, key = lambda i: i['date']) + +for i in range(1, 6): + draw.text((0, font_size * i + 2), conferences[i - 1]['title'], font=font, fill=0) +epd.display(epd.getbuffer(image)) + +# time.sleep(10) +# epd.Clear(0xFF) +epd.sleep() |