home · contact · privacy
Add foreign key restraints, expand and fix tests, add deletion and forking.
[misc] / unite.py
index 14a7e3c4f9ad479539f0cd8398ff5d7494f781a0..8f90e67ea82be45774467f470d7186904bc136d1 100644 (file)
--- a/unite.py
+++ b/unite.py
@@ -3,7 +3,8 @@ from urllib.parse import urlparse
 from income_progress_bars import IncomeProgressHandler 
 from calories import ConsumptionsHandler 
 from ledger import LedgerHandler 
-server_port = 8084
+from todo import TodoHandler 
+server_port = 8081
 
 
 class UnitedRequestHandler(PlomHandler):
@@ -22,41 +23,41 @@ class UnitedRequestHandler(PlomHandler):
         cls.routes[method][path] = service 
 
     def do_POST(self):
-        try: 
-            parsed_url = urlparse(self.path)
-            path_toks = parsed_url.path.split('/')
-            while len(path_toks) > 0:
-                target_path = '/'.join(path_toks)
-                if target_path in self.routes['POST'].keys(): 
-                    self.routes['POST'][target_path](self)
-                    return 
-                path_toks.pop()
-            page = 'nothing to post?'
-            self.send_HTML(page)
-        except PlomException as e:
-            self.fail_400(e)
+        self.try_do(self._do_posts)
+
+    def _do_posts(self):
+        parsed_url = urlparse(self.path)
+        path_toks = parsed_url.path.split('/')
+        while len(path_toks) > 0:
+            target_path = '/'.join(path_toks)
+            if target_path in self.routes['POST'].keys(): 
+                self.routes['POST'][target_path](self)
+                return 
+            path_toks.pop()
+        page = 'nothing to post?'
+        self.send_HTML(page)
 
     def do_GET(self):
-        try: 
-            parsed_url = urlparse(self.path)
-            path_toks = parsed_url.path.split('/')
-            while len(path_toks) > 0:
-                target_path = '/'.join(path_toks)
-                print(target_path)
-                if target_path in self.routes['GET'].keys():                
-                    self.routes['GET'][target_path](self)
-                    return 
-                path_toks.pop()
-            page = 'hi there!<br />'
-            for route in self.routes['GET']:
-                page += f'<a href="{route}"/>{route}</a><br />'
-            self.send_HTML(page)
-        except PlomException as e:
-            self.fail_400(e)
+        self.try_do(self._do_gets)
+
+    def _do_gets(self):
+        parsed_url = urlparse(self.path)
+        path_toks = parsed_url.path.split('/')
+        while len(path_toks) > 0:
+            target_path = '/'.join(path_toks)
+            if target_path in self.routes['GET'].keys():                
+                self.routes['GET'][target_path](self)
+                return 
+            path_toks.pop()
+        page = 'hi there!<br />'
+        for route in self.routes['GET']:
+            page += f'<a href="{route}"/>{route}</a><br />'
+        self.send_HTML(page)
 
 
 if __name__ == "__main__":  
     UnitedRequestHandler.register_app(IncomeProgressHandler)
     UnitedRequestHandler.register_app(ConsumptionsHandler)
     UnitedRequestHandler.register_app(LedgerHandler)
+    UnitedRequestHandler.register_app(TodoHandler)
     run_server(server_port, UnitedRequestHandler)