added time representation

This commit is contained in:
bvn13 2024-10-16 23:47:00 +03:00
parent b3bb8b79f8
commit ce44a0f248
3 changed files with 17 additions and 3 deletions

View File

@ -15,6 +15,7 @@ urllib3 = "^2.2.3"
tornado = "^6.4.1" tornado = "^6.4.1"
asyncio = "^3.4.3" asyncio = "^3.4.3"
scheduler = "^0.8.7" scheduler = "^0.8.7"
pytz = "^2024.2"
[tool.poetry.scripts] [tool.poetry.scripts]
rss-feedler = "src.app:start" rss-feedler = "src.app:start"

View File

@ -4,14 +4,23 @@ from argparse import Namespace
import tornado import tornado
from src.logger import logger as l from src.logger import logger as l
import src.stats as stats import src.stats as stats
from datetime import datetime
from zoneinfo import ZoneInfo
def start_server(settings: list, args: Namespace) -> None: def start_server(settings: list, args: Namespace) -> None:
logger = l.getChild(__name__) logger = l.getChild(__name__)
local_format = "%Y-%m-%d %H:%M:%S"
local_tz = ZoneInfo('Europe/Moscow')
def _get_all_feeds(): def _get_all_feeds():
return [{ 'rss': sets['name'], 'file': f"/feeds/{sets['rss']}" } for sets in settings if os.path.isfile(f"{args.directory}/{sets['rss']}")] return [{ 'rss': sets['name'], 'file': f"/feeds/{sets['rss']}" } for sets in settings if os.path.isfile(f"{args.directory}/{sets['rss']}")]
def _local_now() -> datetime:
dt = stats.get_last_modified_at()
local_dt = dt.astimezone(local_tz)
return local_dt
class MainHandler(tornado.web.RequestHandler): class MainHandler(tornado.web.RequestHandler):
def set_default_headers(self): def set_default_headers(self):
@ -20,7 +29,7 @@ def start_server(settings: list, args: Namespace) -> None:
self.set_header('Access-Control-Allow-Methods', 'GET, OPTIONS') self.set_header('Access-Control-Allow-Methods', 'GET, OPTIONS')
def get(self): def get(self):
self.render("index.html", feeds=_get_all_feeds(), last_modified_at=stats.get_last_modified_at()) self.render("index.html", feeds=_get_all_feeds(), last_modified_at=_local_now().strftime(local_format), tz=f"{local_tz}")
async def start_web_server(): async def start_web_server():

View File

@ -2,17 +2,21 @@
<html> <html>
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>Tornado Chat Demo</title> <title>RSS feedler</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0">
</head> </head>
<body> <body>
<div id="body"> <div id="body">
<h1>Feeds available:</h1> <h1>Feeds available:</h1>
<h3>Last modified at: {{ last_modified_at }}</h3> <h3>Last modified at: {{ last_modified_at }}, {{ tz }}</h3>
<ol> <ol>
{% for feed in feeds %} {% for feed in feeds %}
{% module Template("feed.html", feed=feed) %} {% module Template("feed.html", feed=feed) %}
{% end %} {% end %}
</ol> </ol>
</div> </div>
<footer>
<p>author: <a href="http://t.me/bvn13_blog">bvn13</a></p>
</footer>
</body> </body>
</html> </html>