simple json storage forced sort orders
This commit is contained in:
parent
879fff0eb9
commit
0bed3bfb52
1
app.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
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"
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user