X-Git-Url: https://plomlompom.com/repos/new_day?a=blobdiff_plain;f=unite.py;h=8f90e67ea82be45774467f470d7186904bc136d1;hb=979de59ced9fe3fd3860d19288b42485d7f02346;hp=14a7e3c4f9ad479539f0cd8398ff5d7494f781a0;hpb=389620d37f697f869ed051071db5dead95a152fe;p=misc
diff --git a/unite.py b/unite.py
index 14a7e3c..8f90e67 100644
--- 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!
'
- for route in self.routes['GET']:
- page += f'{route}
'
- 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!
'
+ for route in self.routes['GET']:
+ page += f'{route}
'
+ 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)