From 0bed3bfb52ae20a455996535bb73489a79b100d8 Mon Sep 17 00:00:00 2001 From: crunk Date: Sat, 7 Oct 2023 21:45:19 +0200 Subject: [PATCH] simple json storage forced sort orders --- app.py | 1 + columns.toml | 21 --------------------- simplejsonstorage.py | 7 ++++--- start.py | 1 - 4 files changed, 5 insertions(+), 25 deletions(-) delete mode 100644 columns.toml diff --git a/app.py b/app.py index b33fc29..4e8d8ab 100644 --- a/app.py +++ b/app.py @@ -28,6 +28,7 @@ def create_app(): def update_feeds(json_file): + print("updating feeds from columns.toml file") with open("columns.toml", "rb") as f: column_dict = tomli.load(f) diff --git a/columns.toml b/columns.toml deleted file mode 100644 index e28f2e3..0000000 --- a/columns.toml +++ /dev/null @@ -1,21 +0,0 @@ -[[column]] -urls = ["https://varia.zone/logs/x-y/feed.rss.xml","https://varia.zone/logs/x-y-protocols/feed.rss.xml"] -title = "code" -limit = 5 -sort_order = "random" - -[[column]] -urls = ["https://post.lurk.org/@cmos4040.rss"] -title = "circulations" -sort_order = "reverse" -tag_filter = "electronics" - -[[column]] -urls = ["https://post.lurk.org/tags/radio.rss"] -title = "radio" -sort_order = "reverse-chronological" - -[[column]] -urls = ["https://post.lurk.org/tags/forth.rss"] -title = "forth" -sort_order = "chronological" diff --git a/simplejsonstorage.py b/simplejsonstorage.py index f6a911a..632e0ab 100644 --- a/simplejsonstorage.py +++ b/simplejsonstorage.py @@ -1,11 +1,12 @@ from json import dumps, loads +from collections import OrderedDict from logging import DEBUG, INFO, basicConfig, getLogger from os import environ, mkdir from os.path import exists from pathlib import Path -class SimpleJsonStorage(dict): +class SimpleJsonStorage(OrderedDict): """A simple json file. It is a dictionary which saves to disk on all writes. It is optimised for ease of hacking and accessibility and not for performance or efficiency. @@ -38,7 +39,7 @@ class SimpleJsonStorage(dict): """Save the file to disk.""" try: with open(self.filename, "w") as handle: - handle.write(dumps(self, indent=4, sort_keys=True)) + handle.write(dumps(self, indent=4)) except Exception as exception: message = f"Saving file storage failed: {exception}" self.log.error(message, exc_info=exception) @@ -56,6 +57,6 @@ class SimpleJsonStorage(dict): def update(self, *args, **kwargs): """Update the file.""" - for k, v in dict(*args, **kwargs).items(): + for k, v in OrderedDict(*args, **kwargs).items(): self[k] = v self._dumps() diff --git a/start.py b/start.py index 717d2bc..a270b73 100644 --- a/start.py +++ b/start.py @@ -16,7 +16,6 @@ def index(): json_file = load_json_file() columns = [] for key, value in json_file.items(): - print(key) column = Column(value["title"], value["urls"]) column.set_entries(value["entries"]) columns.append(column)