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)