From b56175fe1310c5bb8d0e820ae7f5ffdd403a4a89 Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 23 Mar 2021 15:47:03 +0100 Subject: [PATCH] event + training colors --- layout.css | 8 ++++++++ sched.py | 10 ++++++++-- vatsched.py | 48 ++++++++++++++++++++++++++++++++++++++++-------- 3 files changed, 56 insertions(+), 10 deletions(-) mode change 100644 => 100755 sched.py diff --git a/layout.css b/layout.css index 252ce87..7db5de7 100644 --- a/layout.css +++ b/layout.css @@ -32,4 +32,12 @@ tr:nth-child(2n) { .colwidth { width: 80px; +} + +.training { + color: #185886; +} + +.event { + color: green; } \ No newline at end of file diff --git a/sched.py b/sched.py old mode 100644 new mode 100755 index 439e33b..7a0f219 --- a/sched.py +++ b/sched.py @@ -1,5 +1,9 @@ +#!/usr/bin/env python3 from vatsched import * +import os +# outputdirectory, filename = os.path.split(__file__) # to place in current directory +outputdirectory = "/home/daniel/html/vatsim" stations = [ "EDWW_CTR", @@ -47,6 +51,8 @@ stations = [ displaydates = EveryXWeeksFromStartdate("26.02.2021", 4, 2) #displaydates = EveryWeekday(1,2) # MONDAY = 0 -#displaydates = WholeWeek() -createImage(displaydates, stations, 'test.jpg') \ No newline at end of file +createImage(displaydates, stations, outputdirectory + os.sep + 'ber-fra-shuttle.jpg') + +#displaydates = WholeWeek() +#createImage(displaydates, stations, outputdirectory + os.sep + 'woche.jpg') \ No newline at end of file diff --git a/vatsched.py b/vatsched.py index 53cbcdf..8d31b16 100644 --- a/vatsched.py +++ b/vatsched.py @@ -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 = "" + color2 = "" + event = 1 + if(booking['training'] == 1): + color1 = "" + color2 = "" + training = 1 + text.append(color1 + abbr + " " + booking['starts_at'].strftime("%H") + "-" + booking['ends_at'].strftime("%H") + color2) if len(text) < 1: text.append("--") return "
".join(text) def maketable(stations, displaydates, bookings): - global abbreviations + global abbreviations, training, event text = "" for date in displaydates: @@ -73,10 +84,22 @@ def maketable(stations, displaydates, bookings): if i > 4: text += "
" i = 0 - return text + "
" + text += "" + + text += "
" + if(training == 1): + text += "Training " + if(event == 1): + text += "Event" + text += "
" + return text -def createImage(displaydates, stations, filename): +def createImage(displaydates, stations, filename): + global abbreviations, training, event + training = event = 0 + abbreviations = {} + 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='C:/Program Files/wkhtmltopdf/bin/wkhtmltoimage.exe') config = imgkit.config(wkhtmltoimage='/usr/bin/wkhtmltoimage')
Stationen