kobo-wall-calendar/main.py

58 lines
1.4 KiB
Python
Raw Normal View History

2022-08-18 22:03:40 +00:00
import argparse
import bottle
2023-09-17 16:06:20 +00:00
import templates
2022-08-18 22:03:40 +00:00
2023-09-17 16:06:20 +00:00
#
2022-08-18 22:03:40 +00:00
2023-09-17 16:06:20 +00:00
def determine_data():
pass
2022-08-18 22:03:40 +00:00
2023-09-17 16:06:20 +00:00
# Template rendering
2022-08-18 22:03:40 +00:00
2023-09-17 16:06:20 +00:00
def render_calendar(events_map, today):
2022-08-18 22:03:40 +00:00
days = []
for day_of_month in range(1, 31 + 1):
day_of_week = (day_of_month - 1) % 7 + 1
week_of_year = day_of_month // 7 + 1
days.append({
'day_of_month': day_of_month,
'day_of_week': day_of_week,
'is_weekend': day_of_week == 6 or day_of_week == 7,
'week_of_year' : week_of_year,
2023-09-17 16:06:20 +00:00
'today': day_of_month == today,
'already_past': day_of_month < today,
2022-08-18 22:03:40 +00:00
'events': events_map.get(day_of_month, []),
})
2023-09-17 16:06:20 +00:00
return bottle.template(templates.TEMPLATE_INDEX, days = days)
## Paths
@bottle.route('/static/<path:path>')
def static(path):
return bottle.static_file(path, root = './static')
@bottle.route('/')
def reddit_index():
events_map = {
15: ['J: Japansk 1'],
19: ['J: Spil Fredagsbar', 'L: Datbar'],
20: ['JL: Regatta'],
}
today = 19
return render_calendar(events_map, today)
2022-08-18 22:03:40 +00:00
## Argument parsing
parser = argparse.ArgumentParser()
parser.add_argument('--hostname', action='store', default = 'localhost', dest='hostname')
parser.add_argument('--port', action='store', default = 8080, dest='port', type = int)
if __name__ == '__main__':
args = parser.parse_args()
bottle.run(host=args.hostname, port=args.port)