From b36ec7c4035ee343c6c3c777dab4ad294f6c817e Mon Sep 17 00:00:00 2001 From: Jon Michael Aanes Date: Fri, 19 Aug 2022 00:03:40 +0200 Subject: [PATCH] Initial prototype --- main.py | 144 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 144 insertions(+) create mode 100644 main.py diff --git a/main.py b/main.py new file mode 100644 index 0000000..33e8639 --- /dev/null +++ b/main.py @@ -0,0 +1,144 @@ +import argparse +import bottle + +TEMPLATE_INDEX = ''' + + + + My calendar + + + +

August 2022

+
+
+
+
Monday
+
Tuesday
+
Wednesday
+
Thursday
+
Friday
+
Saturday
+
Sunday
+ +% for day_info in days: +% if day_info['day_of_week'] == 1: +
+
W{{ day_info['week_of_year'] }}
+% end +
{{ day_info['day_of_month'] }}
+% for event_text in day_info['events']: +
{{ event_text }} +% end + +
+% end +
+
+ + +''' + +## Paths +@bottle.route('/') +def reddit_index(): + events_map = { + 19: ['J: Spil Fredagsbar', 'L: Datbar'], + 20: ['F: Regatta'], + } + + 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, + 'today': day_of_month == 19, + 'events': events_map.get(day_of_month, []), + }) + return bottle.template(TEMPLATE_INDEX, days = days) + +## 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) + +