added updating time at every feed
This commit is contained in:
parent
fd54f2497f
commit
f9cb34c673
@ -11,6 +11,7 @@ import src.stats as stats
|
||||
|
||||
def fetch(settings: list, args: Namespace) -> None:
|
||||
logger = l.getChild(__name__)
|
||||
logger.info("Starting refreshing feeds")
|
||||
for sets in settings:
|
||||
logger.info(f"Working set: {sets}")
|
||||
assert type(sets) == dict
|
||||
@ -34,3 +35,4 @@ def fetch(settings: list, args: Namespace) -> None:
|
||||
except requests.exceptions.ConnectionError as e:
|
||||
logger.warning(f"Unable to fetch {sets['src']}", e)
|
||||
stats.set_last_modified_at(datetime.now())
|
||||
logger.info("Feeds refreshed")
|
@ -1,5 +1,6 @@
|
||||
import asyncio
|
||||
import os
|
||||
import time
|
||||
from argparse import Namespace
|
||||
import tornado
|
||||
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_tz = ZoneInfo('Europe/Moscow')
|
||||
|
||||
def _modification_date(filename):
|
||||
t = os.path.getmtime(filename)
|
||||
return datetime.fromtimestamp(t)
|
||||
|
||||
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:
|
||||
dt = stats.get_last_modified_at()
|
||||
local_dt = dt.astimezone(local_tz)
|
||||
return local_dt
|
||||
if dt is None:
|
||||
dt = datetime.now()
|
||||
return _to_local_tz(dt)
|
||||
|
||||
class MainHandler(tornado.web.RequestHandler):
|
||||
def set_default_headers(self):
|
||||
|
@ -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>
|
@ -4,16 +4,37 @@
|
||||
<meta charset="UTF-8">
|
||||
<title>RSS feedler</title>
|
||||
<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>
|
||||
<body>
|
||||
<div id="body">
|
||||
<h1>Feeds available:</h1>
|
||||
<h3>Last modified at: {{ last_modified_at }}, {{ tz }}</h3>
|
||||
<ol>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>##</th>
|
||||
<th>Feeed</th>
|
||||
<th>Last updated at</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for feed in feeds %}
|
||||
<tr>
|
||||
{% module Template("feed.html", feed=feed) %}
|
||||
</tr>
|
||||
{% end %}
|
||||
</ol>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<footer>
|
||||
<p>author: <a href="http://t.me/bvn13_blog">bvn13</a></p>
|
||||
|
Loading…
Reference in New Issue
Block a user