import argparse import bottle TEMPLATE_INDEX = bottle.SimpleTemplate(name = "templates/index.html") # def determine_data(): pass # Template rendering def render_calendar(events_map, today): 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 == today, 'already_past': day_of_month < today, 'events': events_map.get(day_of_month, []), }) return TEMPLATE_INDEX.render(days = days) ## Paths @bottle.route('/static/') 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) ## 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)