simple json storage forced sort orders

This commit is contained in:
crunk 2023-10-07 21:45:19 +02:00
parent 879fff0eb9
commit 0bed3bfb52
4 changed files with 5 additions and 25 deletions

1
app.py
View File

@ -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)

View File

@ -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"

View File

@ -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()

View File

@ -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)