X-Git-Url: https://plomlompom.com/repos/%7B%7Bprefix%7D%7D/ledger2?a=blobdiff_plain;f=task.py;h=0b8825476353fff066f4b5480c7fcbf2d5ef00b5;hb=0b9590b2c15c246782d9a81e1df24baa73a09765;hp=a1510b0a202571796a5da96262fc115fb3e85a84;hpb=5744cbdb67c253d8a8d54eb9710958a66a64fbb6;p=plomtask diff --git a/task.py b/task.py index a1510b0..0b88254 100755 --- a/task.py +++ b/task.py @@ -1,11 +1,14 @@ #!/usr/bin/env python3 -""" -plom's task manager -""" +"""plom's task manager""" from http.server import BaseHTTPRequestHandler from http.server import HTTPServer +from urllib.parse import urlparse +from os.path import split as path_split +from jinja2 import Environment as JinjaEnv, FileSystemLoader as JinjaFSLoader +from days import Day HTTP_PORT = 8082 +TEMPLATES_DIR = 'templates' class HandledException(Exception): @@ -17,15 +20,33 @@ class TaskHandler(BaseHTTPRequestHandler): def do_GET(self): """Handle any GET request.""" + parsed_url = urlparse(self.path) + site = path_split(parsed_url.path)[1] + if 'calendar' == site: + html = self.do_GET_calendar() + else: + html = self.do_GET_msg('I have nothing to say at this point.') self.send_response(200) self.end_headers() - html = '
hi there!
' self.wfile.write(bytes(html, 'utf-8')) + def do_GET_msg(self, msg): + """Show message.""" + return self.server.jinja.get_template('msg.html').render( + msg=msg) + + def do_GET_calendar(self): + """Show sorted Days.""" + days = [Day('2024-01-03'), Day('2024-01-01'), Day('2024-01-02')] + days.sort() + return self.server.jinja.get_template('calendar.html').render( + days=days) + def main(): """Main loop.""" server = HTTPServer(('localhost', HTTP_PORT), TaskHandler) + server.jinja = JinjaEnv(loader=JinjaFSLoader(TEMPLATES_DIR)) print(f'running at port {HTTP_PORT}') try: server.serve_forever()