From 0357a2c798d47e033504a41d314ec70414178159 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcel=20Gl=C3=A4ser?= <marcel.glaeser@idiv.de> Date: Tue, 16 May 2017 08:52:30 +0200 Subject: [PATCH] try to genereate html from py --- .gitignore | 1 + eventdisplays_html_page.py | 66 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 .gitignore create mode 100644 eventdisplays_html_page.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2d19fc7 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.html diff --git a/eventdisplays_html_page.py b/eventdisplays_html_page.py new file mode 100644 index 0000000..8b56016 --- /dev/null +++ b/eventdisplays_html_page.py @@ -0,0 +1,66 @@ +#!/usr/bin/python + +import requests +import arrow +from ics import Calendar + +url = 'https://portal.idiv.de/ssf/ical/basic.ics?bi=393&ui=1026&pd=171497477d81eb659bd832ffe26c8bfe39d65fc3&v=1' +tz = 'Europe/Berlin' +now = arrow.now(tz) +period = (now.floor('day'), now.replace(weeks=+8)) + +c = Calendar(requests.get(url).text) +my_list = [] +for e in c.events: + if e.begin > period[0] and e.begin < period[1]: + my_list.append((e.name, e.begin.format('DD-MM-YYYY HH:mm:ss'), e.location)) + +event = [my_list[0][0],my_list[1][0],my_list[2][0]] +begin = [my_list[0][1],my_list[1][1],my_list[2][1]] +location = [my_list[0][2],my_list[1][2],my_list[2][2]] + +html_page = """<!DOCTYPE html> + <html> + <head> + <title>Events</title> + <meta charset="utf-8"> + <link href='http://fonts.googleapis.com/css?family=Ubuntu|Ruda' rel='stylesheet' type='text/css'> + <link rel="stylesheet" type="text/css" href="style.css"> + <script type="text/javascript" src="calendar.js"></script> + </head> + <style> + table {{ + width:100%; + }} + table, th, td {{ + border: 1px solid black; + border-collapse: collapse; + }} + th, td {{ + padding: 5px; + text-align: left; + }} + table#t01 tr:nth-child(even) {{ + background-color: #eee; + }} + table#t01 tr:nth-child(odd) {{ + background-color:#fff; + }} + table#t01 th {{ + background-color: black; + color: white; + }} + </style> + </head> + <body> + table id="t01"> + <tr> + <th>{the_event}</th> + <th>{the_date}</th> + <th>{the_location}</th> + </tr> + </body> + </html>""".format(the_event = event[0], the_location = location[0], the_date = begin[0]) + +out_file = open('test.html', 'w') +out_file.write(html_page) -- GitLab