commit c53620a258cb62eafb86b0812a3c9b97db4c63f2 Author: Daniel Date: Sun Mar 21 19:36:13 2021 +0100 initializing diff --git a/layout.css b/layout.css new file mode 100644 index 0000000..252ce87 --- /dev/null +++ b/layout.css @@ -0,0 +1,35 @@ +table { + border-collapse: collapse; + margin-bottom: 10px; +} + +th { + background-color: #185886; + color: white; +} + +th, td { + text-align: center; + border: 1px solid #ccc; + font-size: 10pt; +} + +body { + font-family: 'Ubuntu'; + font-size: 10pt; +} + +tr:nth-child(2n) { + background-color: #f5f5f5; +} + +.abbreviations { + margin-top: 5px; + margin-right: 5px; + float: left; +} + + +.colwidth { + width: 80px; +} \ No newline at end of file diff --git a/sched.py b/sched.py new file mode 100644 index 0000000..439e33b --- /dev/null +++ b/sched.py @@ -0,0 +1,52 @@ +from vatsched import * + + +stations = [ + "EDWW_CTR", + "EDWW_A_CTR", + "EDWW_B_CTR", + "--", + "EDUU_O_CTR", + "EDUU_E_CTR", + "--", + "EDBB_S_APP", + "EDBB_U_APP", + "EDBB_S_DEP", + "EDBB_N_APP", + "--", + "EDDB_N_TWR", + "EDDB_S_TWR", + "EDDB_A_GND", + "EDDB_E_GND", + "EDDB_N_GND", + "EDDB_S_GND", + "EDDB_DEL", + "--", + "EDMM_CTR", + "EDMM_M_CTR", + "EDMM_G_CTR", + "--", + "EDDP_S_APP", + "EDDP_F_APP", + "EDDP_N_APP", + "--", + "EDDP_N_TWR", + "EDDP_S_TWR", + "EDDP_GND", + "EDDP_DEL", + "--", + "EDDC_APP", + "EDDC_TWR", + "EDDC_GND", + "EDDC_A_GND", + "--", + "EDDE_TWR", + "EDDE_GND", + "EDDE_A_GND" +] + +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 diff --git a/vatsched.py b/vatsched.py new file mode 100644 index 0000000..b9e2fa9 --- /dev/null +++ b/vatsched.py @@ -0,0 +1,96 @@ +import imgkit, requests +from dateutil.parser import parse +from datetime import datetime, timedelta + +abbreviations = {} + +def EveryXWeeksFromStartdate(startdate, x, numberofdates = 1): + startdate = parse(startdate) + days = [] + while (len(days) < numberofdates): + startdate += timedelta(days=x*7) + if(datetime.today() <= startdate): + days.append(startdate) + return days + +def EveryWeekday(weekday, numberofdates=1): + startdate = datetime.today() + timedelta((weekday - datetime.today().weekday()) % 7) + days = [] + while(len(days) < numberofdates): + days.append(startdate) + startdate += timedelta(7) + return days + +def WholeWeek(shift = 0): + days=[] + startdate = datetime.today() + timedelta(shift) + for i in range(0,7): + days.append(startdate + timedelta(i)) + return days + + +def getDatePositionData(station, date, bookings): + global abbreviations + text = [] + for booking in bookings[station]: + 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 len(text) < 1: + text.append("--") + return "
".join(text) + +def maketable(stations, displaydates, bookings): + global abbreviations + text = "" + + for date in displaydates: + text += "" % (date.strftime("%a %d.%m.")) + + text += "" + text += "" % (len(displaydates) + 1) + + for station in stations: + if station == "--": + text += "" % (len(displaydates) + 1) + text += "" % (len(displaydates) + 1) + continue + datestext = "" + for date in displaydates: + datestext += "" % (getDatePositionData(station, date, bookings)) + text += "%s" % (station, datestext) + + text += "
Stationen%s
%s
%s
" + + i = 0 + for key in sorted(abbreviations.keys()): + text += "
%s: %s
" % (key, abbreviations[key]) + i += 1 + if i > 4: + text += "
" + i = 0 + return text + "
" + + +def createImage(displaydates, stations, filename): + rawdata = fetchData(displaydates[0], displaydates[-1]) + relbookings = {} + for station in stations: + relbookings[station] = [] + + 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']}) + + text = maketable(stations, displaydates, relbookings) + css = 'layout.css' + config = imgkit.config(wkhtmltoimage='C:/Program Files/wkhtmltopdf/bin/wkhtmltoimage.exe') + options = {'width': (100 + 75 * len(displaydates)), 'disable-smart-width': ''} + imgkit.from_string(text, filename, css=css, config=config, options=options) + return + +def fetchData(startdate = datetime.today(), enddate = (datetime.today() + timedelta(1))): + url = 'https://vatsim-germany.org/api/booking/atc/daterange/%s/%s' % (startdate.strftime("%d.%m.%Y"), enddate.strftime("%d.%m.%Y")) + r = requests.get(url=url,headers={'X-Requested-With': 'XMLHttpRequest'}) + return r.json() \ No newline at end of file