added updating time at every feed

This commit is contained in:
vy.boyko 2024-10-17 19:01:50 +03:00
parent fd54f2497f
commit f9cb34c673
4 changed files with 50 additions and 10 deletions

View File

@ -11,6 +11,7 @@ import src.stats as stats
def fetch(settings: list, args: Namespace) -> None: def fetch(settings: list, args: Namespace) -> None:
logger = l.getChild(__name__) logger = l.getChild(__name__)
logger.info("Starting refreshing feeds")
for sets in settings: for sets in settings:
logger.info(f"Working set: {sets}") logger.info(f"Working set: {sets}")
assert type(sets) == dict assert type(sets) == dict
@ -34,3 +35,4 @@ def fetch(settings: list, args: Namespace) -> None:
except requests.exceptions.ConnectionError as e: except requests.exceptions.ConnectionError as e:
logger.warning(f"Unable to fetch {sets['src']}", e) logger.warning(f"Unable to fetch {sets['src']}", e)
stats.set_last_modified_at(datetime.now()) stats.set_last_modified_at(datetime.now())
logger.info("Feeds refreshed")

View File

@ -1,5 +1,6 @@
import asyncio import asyncio
import os import os
import time
from argparse import Namespace from argparse import Namespace
import tornado import tornado
from src.logger import logger as l from src.logger import logger as l
@ -14,13 +15,27 @@ def start_server(settings: list, args: Namespace) -> None:
local_format = "%Y-%m-%d %H:%M:%S" local_format = "%Y-%m-%d %H:%M:%S"
local_tz = ZoneInfo('Europe/Moscow') local_tz = ZoneInfo('Europe/Moscow')
def _modification_date(filename):
t = os.path.getmtime(filename)
return datetime.fromtimestamp(t)
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 [{
'pos': idx+1,
'rss': sets['name'],
'file': f"/feeds/{sets['rss']}",
'updated_at': _to_local_tz(_modification_date(f"{args.directory}/{sets['rss']}")).strftime(local_format)
} for idx, sets in enumerate(settings) if os.path.isfile(f"{args.directory}/{sets['rss']}")]
def _to_local_tz(dt: datetime) -> datetime:
local_dt = dt.astimezone(local_tz)
return local_dt
def _local_now() -> datetime: def _local_now() -> datetime:
dt = stats.get_last_modified_at() dt = stats.get_last_modified_at()
local_dt = dt.astimezone(local_tz) if dt is None:
return local_dt dt = datetime.now()
return _to_local_tz(dt)
class MainHandler(tornado.web.RequestHandler): class MainHandler(tornado.web.RequestHandler):
def set_default_headers(self): def set_default_headers(self):

View File

@ -1 +1,3 @@
<li id="m{{ feed['rss'] }}"><a href="{% module linkify(feed['file']) %}">{{ feed['rss'] }}</a></li> <td>{{ feed['pos'] }}</td>
<td><a href="{% module linkify(feed['file']) %}">{{ feed['rss'] }}</a></td>
<td>{{ feed['updated_at'] }}</td>

View File

@ -4,16 +4,37 @@
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>RSS feedler</title> <title>RSS feedler</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0">
<style>
table {
border: 2px solid rgb(140 140 140);
}
th,
td {
border: 1px solid rgb(160 160 160);
}
</style>
</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 }}, {{ tz }}</h3> <h3>Last modified at: {{ last_modified_at }}, {{ tz }}</h3>
<ol> <table>
{% for feed in feeds %} <thead>
{% module Template("feed.html", feed=feed) %} <tr>
{% end %} <th>##</th>
</ol> <th>Feeed</th>
<th>Last updated at</th>
</tr>
</thead>
<tbody>
{% for feed in feeds %}
<tr>
{% module Template("feed.html", feed=feed) %}
</tr>
{% end %}
</tbody>
</table>
</div> </div>
<footer> <footer>
<p>author: <a href="http://t.me/bvn13_blog">bvn13</a></p> <p>author: <a href="http://t.me/bvn13_blog">bvn13</a></p>