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):
|
def update_feeds(json_file):
|
||||||
|
print("updating feeds from columns.toml file")
|
||||||
with open("columns.toml", "rb") as f:
|
with open("columns.toml", "rb") as f:
|
||||||
column_dict = tomli.load(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 json import dumps, loads
|
||||||
|
from collections import OrderedDict
|
||||||
from logging import DEBUG, INFO, basicConfig, getLogger
|
from logging import DEBUG, INFO, basicConfig, getLogger
|
||||||
from os import environ, mkdir
|
from os import environ, mkdir
|
||||||
from os.path import exists
|
from os.path import exists
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
class SimpleJsonStorage(dict):
|
class SimpleJsonStorage(OrderedDict):
|
||||||
"""A simple json file.
|
"""A simple json file.
|
||||||
It is a dictionary which saves to disk on all writes. It is optimised for
|
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.
|
ease of hacking and accessibility and not for performance or efficiency.
|
||||||
@ -38,7 +39,7 @@ class SimpleJsonStorage(dict):
|
|||||||
"""Save the file to disk."""
|
"""Save the file to disk."""
|
||||||
try:
|
try:
|
||||||
with open(self.filename, "w") as handle:
|
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:
|
except Exception as exception:
|
||||||
message = f"Saving file storage failed: {exception}"
|
message = f"Saving file storage failed: {exception}"
|
||||||
self.log.error(message, exc_info=exception)
|
self.log.error(message, exc_info=exception)
|
||||||
@ -56,6 +57,6 @@ class SimpleJsonStorage(dict):
|
|||||||
|
|
||||||
def update(self, *args, **kwargs):
|
def update(self, *args, **kwargs):
|
||||||
"""Update the file."""
|
"""Update the file."""
|
||||||
for k, v in dict(*args, **kwargs).items():
|
for k, v in OrderedDict(*args, **kwargs).items():
|
||||||
self[k] = v
|
self[k] = v
|
||||||
self._dumps()
|
self._dumps()
|
||||||
|
1
start.py
1
start.py
@ -16,7 +16,6 @@ def index():
|
|||||||
json_file = load_json_file()
|
json_file = load_json_file()
|
||||||
columns = []
|
columns = []
|
||||||
for key, value in json_file.items():
|
for key, value in json_file.items():
|
||||||
print(key)
|
|
||||||
column = Column(value["title"], value["urls"])
|
column = Column(value["title"], value["urls"])
|
||||||
column.set_entries(value["entries"])
|
column.set_entries(value["entries"])
|
||||||
columns.append(column)
|
columns.append(column)
|
||||||
|
Loading…
Reference in New Issue
Block a user