use json5 instead lol

toml sucks add null when
This commit is contained in:
io 2021-06-18 10:38:53 +00:00
parent 79301382cd
commit 944e2fc3a5
5 changed files with 8 additions and 9 deletions

1
.gitignore vendored
View File

@ -10,6 +10,7 @@ __pycache__/
.vscode/
.editorconfig
.*.swp
# couldn't decide on a config format lol
config.json
config.toml
venv/

View File

@ -23,7 +23,7 @@ pleroma-ebooks uses ActivityPub to download posts. This means that it is not dep
I recommend that you create your bot's account on a Mastodon instance. Creating a bot on a Pleroma instance means that your bot will be unable to reply, although posting will work just fine. However, even if your bot is on a Mastodon instance, it will be able to learn from any Pleroma or Misskey users just fine.
## Configuration
Configuring pleroma-ebooks is accomplished by editing `config.toml`. If you want to use a different file for configuration, specify it with the `--cfg` argument. For example, if you want to use `/home/lynne/c.toml` instead, you would run `python3 fetch_posts.py --cfg /home/lynne/c.toml` instead of just `python3 fetch_posts.py`
Configuring pleroma-ebooks is accomplished by editing `config.json`. If you want to use a different file for configuration, specify it with the `--cfg` argument. For example, if you want to use `/home/lynne/c.json` instead, you would run `python3 fetch_posts.py --cfg /home/lynne/c.json` instead of just `python3 fetch_posts.py`
| Setting | Default | Meaning |
|--------------------------|-----------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|

View File

@ -12,7 +12,6 @@ import aiohttp
import argparse
import functions
import contextlib
import pytomlpp as toml
from http import HTTPStatus
from pleroma import Pleroma, http_session_factory
@ -69,7 +68,7 @@ async def main():
try:
following = await client.following()
except aiohttp.ClientResponseError as exc:
if exc.code == HTTPStatus.FORBIDDEN:
if exc.status == HTTPStatus.FORBIDDEN:
print(f'The provided access token in {args.cfg} is invalid.', file=sys.stderr)
sys.exit(1)
@ -128,7 +127,7 @@ async def fetch_posts(cfg, http, cur, acc):
done = True
break
except aiohttp.ClientResponseError as exc:
if exc.code == HTTPStatus.TOO_MANY_REQUESTS:
if exc.status == HTTPStatus.TOO_MANY_REQUESTS:
print("We're rate limited. Skipping to next account.")
done = True
break

View File

@ -8,15 +8,15 @@ import shutil
import sqlite3
import argparse
import markovify
import json5 as json
import multiprocessing
import pytomlpp as toml
from random import randint
from bs4 import BeautifulSoup
def arg_parser_factory(*, description):
parser = argparse.ArgumentParser(description=description)
parser.add_argument(
'-c', '--cfg', dest='cfg', default='config.toml', nargs='?',
'-c', '--cfg', dest='cfg', default='config.json', nargs='?',
help='Specify a custom location for the config file.'
)
return parser
@ -25,12 +25,11 @@ def parse_args(*, description):
return arg_parser_factory(description=description).parse_args()
def load_config(cfg_path):
# TOML doesn't support null here so we have to use JSON 😒
with open('config.defaults.json') as f:
cfg = json.load(f)
with open(cfg_path) as f:
cfg.update(toml.load(f))
cfg.update(json.load(f))
if not cfg['site'].startswith('https://') and not cfg['site'].startswith('http://'):
print("Site must begin with 'https://' or 'http://'. Value '{0}' is invalid - try 'https://{0}' instead.".format(cfg['site']), file=sys.stderr)

View File

@ -1,6 +1,6 @@
markovify ~= 0.9.0
beautifulsoup4 ~= 4.9
aiohttp ~= 3.0
pytomlpp ~= 1.0
json5 ~= 0.9.5
anyio ~= 3.0
asqlite @ git+https://github.com/Rapptz/asqlite.git