|
@@ -1,8 +1,10 @@
|
|
|
-import imgkit, requests
|
|
|
+import imgkit, requests, os
|
|
|
from dateutil.parser import parse
|
|
|
from datetime import datetime, timedelta
|
|
|
|
|
|
abbreviations = {}
|
|
|
+training = 0
|
|
|
+event = 0
|
|
|
|
|
|
def EveryXDaysFromStartdate(startdate, x, numberofdates = 1):
|
|
|
startdate = parse(startdate)
|
|
@@ -33,19 +35,28 @@ def WholeWeek(shift = 0):
|
|
|
|
|
|
|
|
|
def getDatePositionData(station, date, bookings):
|
|
|
- global abbreviations
|
|
|
+ global abbreviations, training, event
|
|
|
text = []
|
|
|
for booking in bookings[station]:
|
|
|
+ color1 = color2 = ""
|
|
|
if date.date() == booking['starts_at'].date():
|
|
|
abbr = booking['firstname'][:2] + booking['lastname'].split(" ")[-1][:2]
|
|
|
abbreviations[abbr] = booking['firstname'] + " " + booking['lastname']
|
|
|
- text.append(abbr + " " + booking['starts_at'].strftime("%H") + "-" + booking['ends_at'].strftime("%H"))
|
|
|
+ if(booking['event'] == 1):
|
|
|
+ color1 = "<span class='event'>"
|
|
|
+ color2 = "</span>"
|
|
|
+ event = 1
|
|
|
+ if(booking['training'] == 1):
|
|
|
+ color1 = "<span class='training'>"
|
|
|
+ color2 = "</span>"
|
|
|
+ training = 1
|
|
|
+ text.append(color1 + abbr + " " + booking['starts_at'].strftime("%H") + "-" + booking['ends_at'].strftime("%H") + color2)
|
|
|
if len(text) < 1:
|
|
|
text.append("--")
|
|
|
return "<br>".join(text)
|
|
|
|
|
|
def maketable(stations, displaydates, bookings):
|
|
|
- global abbreviations
|
|
|
+ global abbreviations, training, event
|
|
|
text = "<table><tr><th>Stationen</th>"
|
|
|
|
|
|
for date in displaydates:
|
|
@@ -73,10 +84,22 @@ def maketable(stations, displaydates, bookings):
|
|
|
if i > 4:
|
|
|
text += "</div><div class='abbreviations'>"
|
|
|
i = 0
|
|
|
- return text + "</div>"
|
|
|
+ text += "</div>"
|
|
|
|
|
|
+ text += "<div style='clear:both'>"
|
|
|
+ if(training == 1):
|
|
|
+ text += "<span class='training'>Training </span>"
|
|
|
+ if(event == 1):
|
|
|
+ text += "<span class='event'>Event</span>"
|
|
|
+ text += "</div>"
|
|
|
+ return text
|
|
|
+
|
|
|
+
|
|
|
+def createImage(displaydates, stations, filename):
|
|
|
+ global abbreviations, training, event
|
|
|
+ training = event = 0
|
|
|
+ abbreviations = {}
|
|
|
|
|
|
-def createImage(displaydates, stations, filename):
|
|
|
rawdata = fetchData(displaydates[0], displaydates[-1])
|
|
|
relbookings = {}
|
|
|
for station in stations:
|
|
@@ -84,10 +107,19 @@ def createImage(displaydates, stations, filename):
|
|
|
|
|
|
for datum in rawdata:
|
|
|
if datum['station']['ident'] in stations:
|
|
|
- relbookings[datum['station']['ident']].append({'starts_at': parse(datum['starts_at']), 'ends_at': parse(datum['ends_at']), 'lastname': datum['controller']['lastname'], 'firstname': datum['controller']['firstname']})
|
|
|
+ relbookings[datum['station']['ident']].append({
|
|
|
+ 'starts_at': parse(datum['starts_at']),
|
|
|
+ 'ends_at': parse(datum['ends_at']),
|
|
|
+ 'lastname': datum['controller']['lastname'],
|
|
|
+ 'firstname': datum['controller']['firstname'],
|
|
|
+ 'training': datum['training'],
|
|
|
+ 'event': datum['event']
|
|
|
+ })
|
|
|
|
|
|
text = maketable(stations, displaydates, relbookings)
|
|
|
- css = 'layout.css'
|
|
|
+
|
|
|
+ directory, dontcare = os.path.split(__file__)
|
|
|
+ css = directory + os.sep + 'layout.css'
|
|
|
options = {'width': (100 + 75 * len(displaydates)), 'disable-smart-width': ''}
|
|
|
|
|
|
config = imgkit.config(wkhtmltoimage='/usr/bin/wkhtmltoimage')
|