From 944e2fc3a58fb2fd0be2a0bcc635c4a124574db9 Mon Sep 17 00:00:00 2001 From: io Date: Fri, 18 Jun 2021 10:38:53 +0000 Subject: [PATCH] use json5 instead lol toml sucks add null when --- .gitignore | 1 + README.md | 2 +- fetch_posts.py | 5 ++--- functions.py | 7 +++---- requirements.txt | 2 +- 5 files changed, 8 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index c6ae646..52b5816 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,7 @@ __pycache__/ .vscode/ .editorconfig .*.swp +# couldn't decide on a config format lol config.json config.toml venv/ diff --git a/README.md b/README.md index 0622f08..5b8b09b 100644 --- a/README.md +++ b/README.md @@ -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 | |--------------------------|-----------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| diff --git a/fetch_posts.py b/fetch_posts.py index 0da6d87..1b610ac 100755 --- a/fetch_posts.py +++ b/fetch_posts.py @@ -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 diff --git a/functions.py b/functions.py index d0a549e..46d3b3f 100755 --- a/functions.py +++ b/functions.py @@ -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) diff --git a/requirements.txt b/requirements.txt index 9b7008d..d53bcf1 100644 --- a/requirements.txt +++ b/requirements.txt @@ -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