isort and formatting clean up

This commit is contained in:
crunk 2023-07-16 22:30:32 +02:00
parent f6e9b8f4ad
commit 805d5b5b2b
6 changed files with 61 additions and 54 deletions

3
app.py
View File

@ -1,5 +1,6 @@
import os
import json
import os
import flask_apscheduler
import tomli
from flask import Flask

View File

@ -1,7 +1,8 @@
import random
import json
import random
from datetime import datetime
from time import mktime
from parse_rss_feeds import parse_rss_feeds

View File

@ -1,6 +1,7 @@
from feedparser import parse
import random
from feedparser import parse
def parse_single_rss_feed(url, entries):
feed = parse(url)

View File

@ -1,8 +1,8 @@
import tomli
from column import Column
from parse_rss_feeds import parse_rss_feeds
with open("columns.toml", "rb") as f:
column_dict = tomli.load(f)
columns_file = column_dict["column"]

View File

@ -1,60 +1,61 @@
from json import dumps, loads
from logging import DEBUG, INFO, basicConfig, getLogger
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
class SimpleJsonStorage(dict):
"""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.
Written by decentral1se, as part of:
https://git.vvvvvvaria.org/decentral1se/xbotlib/src/branch/main/xbotlib.py
"""
"""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.
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__)
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)
self._loads()
self.update(*args, **kwargs)
def _loads(self):
"""Load the file."""
if not exists(self.filename):
return
def _loads(self):
"""Load the file."""
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)
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 file 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 _dumps(self):
"""Save the file 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 file."""
super().__setitem__(key, val)
self._dumps()
def __setitem__(self, key, val):
"""Write data to the file."""
super().__setitem__(key, val)
self._dumps()
def __delitem__(self, key):
"""Remove data from the file."""
super().__delitem__(key)
self._dumps()
def __delitem__(self, key):
"""Remove data from the file."""
super().__delitem__(key)
self._dumps()
def update(self, *args, **kwargs):
"""Update the file."""
for k, v in dict(*args, **kwargs).items():
self[k] = v
self._dumps()
def update(self, *args, **kwargs):
"""Update the file."""
for k, v in dict(*args, **kwargs).items():
self[k] = v
self._dumps()

View File

@ -1,10 +1,12 @@
import tomli
import os
import json
import os
import tomli
from flask import render_template
from simplejsonstorage import SimpleJsonStorage
from app import create_app
from column import Column
from simplejsonstorage import SimpleJsonStorage
APP = create_app()
@ -27,6 +29,7 @@ def load_json_file():
)
return json_file
if __name__ == "__main__":
APP.debug = True
APP.run(port=5000)