forked from varia/multifeeder
7 changed files with 300 additions and 259 deletions
@ -1,9 +1,2 @@ |
|||
https://vvvvvvaria.org/feeds/all-nl.rss.xml |
|||
https://vvvvvvaria.org/en/feeds/all-en.rss.xml |
|||
https://post.lurk.org/tags/varia.rss |
|||
https://post.lurk.org/tags/sometimes.rss |
|||
https://a-nourishing-network.radical-openness.org/feeds/feed.rss |
|||
https://vvvvvvaria.org/logs/x-y/feed.rss.xml |
|||
https://vvvvvvaria.org/logs/atnofs-varia/feed.rss.xml |
|||
https://vvvvvvaria.org/logs/pub.club/feed.rss.xml |
|||
https://vvvvvvaria.org/logs/hold-and-release/feed.rss.xml |
|||
https://post.lurk.org/users/cmos4040.rss |
|||
|
@ -0,0 +1,25 @@ |
|||
[tool.black] |
|||
line-length = 79 |
|||
target-version = ['py37', 'py38', 'py39'] |
|||
include = '\.pyi?$' |
|||
exclude = ''' |
|||
/( |
|||
\.eggs |
|||
| \.git |
|||
| \.hg |
|||
| \.mypy_cache |
|||
| \.tox |
|||
| \.venv |
|||
| _build |
|||
| buck-out |
|||
| build |
|||
| dist |
|||
|
|||
# The following are specific to Black, you probably don't want those. |
|||
| blib2to3 |
|||
| tests/data |
|||
| profiling |
|||
)/ |
|||
''' |
|||
|
|||
|
@ -1,61 +1,62 @@ |
|||
from os import environ, mkdir |
|||
from os.path import exists |
|||
from pathlib import Path |
|||
from logging import DEBUG, INFO, basicConfig, getLogger |
|||
from json import dumps, loads |
|||
from pathlib import Path |
|||
from logging import DEBUG, INFO, basicConfig, getLogger |
|||
from json import dumps, loads |
|||
|
|||
|
|||
class SimpleDatabase(dict): |
|||
"""A simple database. |
|||
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. |
|||
|
|||
Written by decentral1se, as part of: |
|||
https://git.vvvvvvaria.org/decentral1se/xbotlib/src/branch/main/xbotlib.py |
|||
""" |
|||
|
|||
def __init__(self, filename, log, *args, **kwargs): |
|||
"""Initialise the object.""" |
|||
self.filename = Path(filename).absolute() |
|||
self.log = getLogger(__name__) |
|||
|
|||
self._loads() |
|||
self.update(*args, **kwargs) |
|||
|
|||
def _loads(self): |
|||
"""Load the database.""" |
|||
if not exists(self.filename): |
|||
return |
|||
|
|||
try: |
|||
with open(self.filename, "r") as handle: |
|||
self.update(loads(handle.read())) |
|||
except Exception as exception: |
|||
message = f"Loading file storage failed: {exception}" |
|||
self.log.error(message, exc_info=exception) |
|||
exit(1) |
|||
|
|||
def _dumps(self): |
|||
"""Save the databse to disk.""" |
|||
try: |
|||
with open(self.filename, "w") as handle: |
|||
handle.write(dumps(self, indent=4, sort_keys=True)) |
|||
except Exception as exception: |
|||
message = f"Saving file storage failed: {exception}" |
|||
self.log.error(message, exc_info=exception) |
|||
exit(1) |
|||
|
|||
def __setitem__(self, key, val): |
|||
"""Write data to the database.""" |
|||
super().__setitem__(key, val) |
|||
self._dumps() |
|||
|
|||
def __delitem__(self, key): |
|||
"""Remove data from the database.""" |
|||
super().__delitem__(key) |
|||
self._dumps() |
|||
|
|||
def update(self, *args, **kwargs): |
|||
"""Update the database.""" |
|||
for k, v in dict(*args, **kwargs).items(): |
|||
self[k] = v |
|||
self._dumps() |
|||
"""A simple database. |
|||
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. |
|||
|
|||
Written by decentral1se, as part of: |
|||
https://git.vvvvvvaria.org/decentral1se/xbotlib/src/branch/main/xbotlib.py |
|||
""" |
|||
|
|||
def __init__(self, filename, log, *args, **kwargs): |
|||
"""Initialise the object.""" |
|||
self.filename = Path(filename).absolute() |
|||
self.log = getLogger(__name__) |
|||
|
|||
self._loads() |
|||
self.update(*args, **kwargs) |
|||
|
|||
def _loads(self): |
|||
"""Load the database.""" |
|||
if not exists(self.filename): |
|||
return |
|||
|
|||
try: |
|||
with open(self.filename, "r") as handle: |
|||
self.update(loads(handle.read())) |
|||
except Exception as exception: |
|||
message = f"Loading file storage failed: {exception}" |
|||
self.log.error(message, exc_info=exception) |
|||
exit(1) |
|||
|
|||
def _dumps(self): |
|||
"""Save the databse to disk.""" |
|||
try: |
|||
with open(self.filename, "w") as handle: |
|||
handle.write(dumps(self, indent=4, sort_keys=True)) |
|||
except Exception as exception: |
|||
message = f"Saving file storage failed: {exception}" |
|||
self.log.error(message, exc_info=exception) |
|||
exit(1) |
|||
|
|||
def __setitem__(self, key, val): |
|||
"""Write data to the database.""" |
|||
super().__setitem__(key, val) |
|||
self._dumps() |
|||
|
|||
def __delitem__(self, key): |
|||
"""Remove data from the database.""" |
|||
super().__delitem__(key) |
|||
self._dumps() |
|||
|
|||
def update(self, *args, **kwargs): |
|||
"""Update the database.""" |
|||
for k, v in dict(*args, **kwargs).items(): |
|||
self[k] = v |
|||
self._dumps() |
|||
|
Loading…
Reference in new issue