mirror of
https://codeberg.org/Reuh/feather.git
synced 2025-10-27 18:19:32 +00:00
feat: handle item updates
This commit is contained in:
parent
9185ab9eb0
commit
f52747b516
2 changed files with 19 additions and 8 deletions
|
|
@ -23,5 +23,5 @@
|
||||||
- [x] Edge cases: mark as read during sync (if marked as read on server or not)
|
- [x] Edge cases: mark as read during sync (if marked as read on server or not)
|
||||||
- [x] Proper filename escaping
|
- [x] Proper filename escaping
|
||||||
- [ ] Command to force regenerate all HTML files (incl. recompute datetimes & paths)
|
- [ ] Command to force regenerate all HTML files (incl. recompute datetimes & paths)
|
||||||
- [ ] Handle item updates
|
- [x] Handle item updates
|
||||||
- [ ] Actually think about the issues created by the duplicate warning
|
- [ ] Actually think about the issues created by the duplicate warning
|
||||||
|
|
|
||||||
25
main.py
25
main.py
|
|
@ -146,7 +146,7 @@ def synchronize_with_server(config, client_session):
|
||||||
config.update_lock.touch()
|
config.update_lock.touch()
|
||||||
print("Synchronizing with server...")
|
print("Synchronizing with server...")
|
||||||
|
|
||||||
new_items = 0
|
new_items, updated_items = 0, 0
|
||||||
grabbed_item_paths = []
|
grabbed_item_paths = []
|
||||||
|
|
||||||
folders = client_session.list_folders()
|
folders = client_session.list_folders()
|
||||||
|
|
@ -154,7 +154,7 @@ def synchronize_with_server(config, client_session):
|
||||||
print(f" Updating folder {folder_name}")
|
print(f" Updating folder {folder_name}")
|
||||||
|
|
||||||
def process(item_ids):
|
def process(item_ids):
|
||||||
nonlocal new_items, grabbed_item_paths
|
nonlocal new_items, updated_items, grabbed_item_paths
|
||||||
if len(item_ids) > 0:
|
if len(item_ids) > 0:
|
||||||
item_contents = client_session.get_stream_items_contents(item_ids=item_ids)
|
item_contents = client_session.get_stream_items_contents(item_ids=item_ids)
|
||||||
for item_content in item_contents.items:
|
for item_content in item_contents.items:
|
||||||
|
|
@ -177,13 +177,24 @@ def synchronize_with_server(config, client_session):
|
||||||
|
|
||||||
json_path = config.json_root / f"{ sha256(item_json["id"].encode("utf-8")).hexdigest() }.json"
|
json_path = config.json_root / f"{ sha256(item_json["id"].encode("utf-8")).hexdigest() }.json"
|
||||||
grabbed_item_paths.append(json_path)
|
grabbed_item_paths.append(json_path)
|
||||||
|
|
||||||
|
write_files, updating = False, False
|
||||||
if not json_path.exists():
|
if not json_path.exists():
|
||||||
|
write_files = True
|
||||||
|
new_items += 1
|
||||||
|
else:
|
||||||
|
old_item_json = json.load(json_path.open("r"))
|
||||||
|
if item_json["updated"] > old_item_json["updated"]:
|
||||||
|
write_files, updating = True, True
|
||||||
|
updated_items += 1
|
||||||
|
|
||||||
|
if write_files:
|
||||||
# write JSON
|
# write JSON
|
||||||
with json_path.open("w") as f:
|
with json_path.open("w") as f:
|
||||||
json.dump(item_json, f)
|
json.dump(item_json, f)
|
||||||
# write HTML
|
# write HTML
|
||||||
generate_html_for_item(config, item_json)
|
generate_html_for_item(config, item_json, regenerate=updating)
|
||||||
new_items += 1
|
|
||||||
|
|
||||||
continuation = None
|
continuation = None
|
||||||
while continuation != '':
|
while continuation != '':
|
||||||
|
|
@ -203,13 +214,13 @@ def synchronize_with_server(config, client_session):
|
||||||
item_path.unlink()
|
item_path.unlink()
|
||||||
removed_items += 1
|
removed_items += 1
|
||||||
|
|
||||||
print(f"Synchronization successful ({new_items} new items, {removed_items} removed)")
|
print(f"Synchronization successful ({new_items} new items, {updated_items} updated, {removed_items} removed)")
|
||||||
config.update_lock.unlink()
|
config.update_lock.unlink()
|
||||||
|
|
||||||
def generate_html_for_item(config, item_json):
|
def generate_html_for_item(config, item_json, regenerate=False):
|
||||||
# Write HTML file for a JSON object
|
# Write HTML file for a JSON object
|
||||||
html_path = config.html_root / item_json["html_path"]
|
html_path = config.html_root / item_json["html_path"]
|
||||||
if html_path.exists():
|
if html_path.exists() and not regenerate:
|
||||||
print(f"WARNING: a file already exist for {html_path}. Either the feed has duplicate entries, or something has gone terribly wrong.")
|
print(f"WARNING: a file already exist for {html_path}. Either the feed has duplicate entries, or something has gone terribly wrong.")
|
||||||
else:
|
else:
|
||||||
with html_path.open("w") as f:
|
with html_path.open("w") as f:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue