added last modified date into web page
This commit is contained in:
parent
4cc4e7922e
commit
0be2fcbbe5
@ -1,3 +1,4 @@
|
||||
from datetime import datetime
|
||||
from argparse import Namespace
|
||||
|
||||
import requests.exceptions
|
||||
@ -5,6 +6,7 @@ from requests import Session
|
||||
from requests.adapters import HTTPAdapter
|
||||
from urllib3.util import Retry
|
||||
from src.logger import logger as l
|
||||
import stats
|
||||
|
||||
|
||||
def fetch(settings: list, args: Namespace) -> None:
|
||||
@ -31,3 +33,4 @@ def fetch(settings: list, args: Namespace) -> None:
|
||||
rss.write(chunk)
|
||||
except requests.exceptions.ConnectionError as e:
|
||||
logger.warning(f"Unable to fetch {sets['src']}", e)
|
||||
stats.set_last_modified_at(datetime.now())
|
@ -1,8 +1,9 @@
|
||||
import asyncio
|
||||
import os, fnmatch
|
||||
import os
|
||||
from argparse import Namespace
|
||||
import tornado
|
||||
from src.logger import logger as l
|
||||
import stats
|
||||
|
||||
|
||||
def start_server(settings: list, args: Namespace) -> None:
|
||||
@ -10,7 +11,7 @@ def start_server(settings: list, args: Namespace) -> None:
|
||||
|
||||
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': f, 'file': f"/feeds/{f}" } for f in fnmatch.filter(os.listdir(args.directory), '*.xml')]
|
||||
|
||||
|
||||
class MainHandler(tornado.web.RequestHandler):
|
||||
def set_default_headers(self):
|
||||
@ -19,7 +20,7 @@ def start_server(settings: list, args: Namespace) -> None:
|
||||
self.set_header('Access-Control-Allow-Methods', 'GET, OPTIONS')
|
||||
|
||||
def get(self):
|
||||
self.render("index.html", feeds=_get_all_feeds())
|
||||
self.render("index.html", feeds=_get_all_feeds(), last_modified_at=stats.get_last_modified_at())
|
||||
|
||||
|
||||
async def start_web_server():
|
||||
|
11
src/stats.py
Normal file
11
src/stats.py
Normal file
@ -0,0 +1,11 @@
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
|
||||
_last_modified_at: Optional[datetime] = None
|
||||
|
||||
def set_last_modified_at(dt: datetime) -> None:
|
||||
global _last_modified_at
|
||||
_last_modified_at = dt
|
||||
|
||||
def get_last_modified_at() -> Optional[datetime]:
|
||||
return _last_modified_at
|
@ -7,6 +7,7 @@
|
||||
<body>
|
||||
<div id="body">
|
||||
<h1>Feeds available:</h1>
|
||||
<h3>Last modified at: {{ last_modified_at }}</h3>
|
||||
<ol>
|
||||
{% for feed in feeds %}
|
||||
{% module Template("feed.html", feed=feed) %}
|
||||
|
Loading…
Reference in New Issue
Block a user