diff --git a/cry/web.py b/cry/web.py index 1717cab..420f8c0 100644 --- a/cry/web.py +++ b/cry/web.py @@ -5,12 +5,13 @@ import functools import html import http.server import io +import pathlib import time import traceback import threading import urllib.parse -from typing import Any, Callable, Concatenate, ParamSpec, Protocol +from typing import Callable, Concatenate, ParamSpec from . import database from . import feed @@ -194,7 +195,9 @@ class EventConsumer: return Event(event=None, data=None, id=None) +############################################################################### # Background Tasks +############################################################################### class BackgroundTask: @@ -335,6 +338,8 @@ class Handler(http.server.BaseHTTPRequestHandler): def do_GET(self): if self.path == "/": return self.serve_feeds() + elif self.path == "/style.css": + return self.serve_style() elif self.path == "/refresh-status": return self.serve_status() elif self.path == "/subscribe-status": @@ -433,26 +438,28 @@ class Handler(http.server.BaseHTTPRequestHandler): self.wfile.flush() def serve_status(self): - global REFRESH_TASK - + # TODO: FIX STYLES TO BE INLINE FOR SPEED I GUESS buffer = io.StringIO() buffer.write( """
+ +More than one feed was found. Choose the feed to subscribe to.
@@ -603,6 +599,22 @@ class Handler(http.server.BaseHTTPRequestHandler): self.end_headers() self.wfile.write(response) + def serve_style(self): + self.write_file( + pathlib.Path(__file__).parent / "static" / "style.css", + content_type="text/css", + ) + + def write_file(self, path: pathlib.Path, content_type: str): + with open(path, "rb") as file: + content = file.read() + + self.send_response(200) + self.send_header("content-type", content_type) + self.send_header("content-length", str(len(content))) + self.end_headers() + self.wfile.write(content) + def serve(): with http.server.ThreadingHTTPServer(("", 8000), Handler) as server: