Browse Source

simple json storage forced sort orders

main
crunk 1 year ago
parent
commit
0bed3bfb52
  1. 1
      app.py
  2. 21
      columns.toml
  3. 7
      simplejsonstorage.py
  4. 1
      start.py

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

21
columns.toml

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

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

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

Loading…
Cancel
Save