mirror of
https://codeberg.org/Reuh/feather.git
synced 2025-10-27 18:19:32 +00:00
feat: store formatted datetime in json
This commit is contained in:
parent
92e3da6b82
commit
75d9367e4f
1 changed files with 7 additions and 4 deletions
11
main.py
11
main.py
|
|
@ -115,13 +115,15 @@ def get_html_path(config, item_json):
|
|||
folder_directory = config.html_root / escape_filename(item_json["folder"])
|
||||
folder_directory.mkdir(exist_ok=True)
|
||||
|
||||
datetime_published = datetime.fromtimestamp(item_json["published"], config.timezone).strftime(config.time_format)
|
||||
html_name = escape_filename(f"{datetime_published}\t[{item_json["origin_title"]}]\t{item_json["title"]}.html")
|
||||
html_name = escape_filename(f"{item_json["published_formatted"]}\t[{item_json["origin_title"]}]\t{item_json["title"]}.html")
|
||||
html_name = html_name[:max_filename_length] + '….html' if len(html_name) > max_filename_length else html_name
|
||||
|
||||
html_path = folder_directory / html_name
|
||||
return html_path
|
||||
|
||||
def format_datetime(config, timestamp):
|
||||
return datetime.fromtimestamp(timestamp, config.timezone).strftime(config.time_format)
|
||||
|
||||
def synchronize_with_server(config, client_session):
|
||||
# Synchronize items from the server, generating and deleting JSON and HTML files accordingly
|
||||
config.update_lock.touch()
|
||||
|
|
@ -144,7 +146,9 @@ def synchronize_with_server(config, client_session):
|
|||
"folder": folder_name,
|
||||
"title": item_content.title,
|
||||
"published": item_content.published,
|
||||
"published_formatted": format_datetime(config, item_content.published),
|
||||
"updated": item_content.updated,
|
||||
"updated_formatted": format_datetime(config, item_content.updated),
|
||||
"author": item_content.author,
|
||||
"summary": item_content.summary.content,
|
||||
"content": item_content.content.content,
|
||||
|
|
@ -187,7 +191,6 @@ def synchronize_with_server(config, client_session):
|
|||
|
||||
def generate_html_for_item(config, item_json):
|
||||
# Write HTML file for a JSON object
|
||||
datetime_published = datetime.fromtimestamp(item_json["published"], config.timezone).strftime(config.time_format)
|
||||
html_path = config.html_root / item_json["html_path"]
|
||||
if html_path.exists():
|
||||
print(f"WARNING: a file already exist for {html_path}. Either the feed has duplicate entries, or something has gone terribly wrong.")
|
||||
|
|
@ -205,7 +208,7 @@ def generate_html_for_item(config, item_json):
|
|||
<style>a{{color:palevioletred; text-decoration:none;}}</style>
|
||||
<article style="max-width:60rem; margin:auto;">
|
||||
<p style="display:flex; flex-direction:row; justify-content:space-between;">
|
||||
<span>{datetime_published}</span>
|
||||
<span>{item_json["published_formatted"]}</span>
|
||||
<span><a href="{item_json["origin_url"]}">{item_json["origin_title"]}</a></span>
|
||||
</p>
|
||||
<h1><a href="{item_json["canonical_url"]}">{item_json["title"]}</a></h1>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue