event + training colors

This commit is contained in:
2021-03-23 15:47:03 +01:00
parent 28306ae7f6
commit b56175fe13
3 changed files with 56 additions and 10 deletions

View File

@@ -32,4 +32,12 @@ tr:nth-child(2n) {
.colwidth {
width: 80px;
}
.training {
color: #185886;
}
.event {
color: green;
}

10
sched.py Normal file → Executable file
View File

@@ -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')
createImage(displaydates, stations, outputdirectory + os.sep + 'ber-fra-shuttle.jpg')
#displaydates = WholeWeek()
#createImage(displaydates, stations, outputdirectory + os.sep + 'woche.jpg')

View File

@@ -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):
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')