diff --git a/gen.py b/gen.py index 9654f7e..c34dac5 100755 --- a/gen.py +++ b/gen.py @@ -4,7 +4,7 @@ # file, You can obtain one at http://mozilla.org/MPL/2.0/. from mastodon import Mastodon -import argparse, sys, traceback +import argparse, sys, traceback, json import create parser = argparse.ArgumentParser(description='Generate and post a toot.') @@ -15,12 +15,12 @@ parser.add_argument('-s', '--simulate', dest='simulate', action='store_true', args = parser.parse_args() -api_base_url = "https://botsin.space" #todo: this shouldn't be hardcoded +cfg = json.load(open('config.json', 'r')) client = Mastodon( client_id="clientcred.secret", access_token="usercred.secret", - api_base_url=api_base_url) + api_base_url=cfg['site']) toot = create.make_toot() if not args.simulate: diff --git a/main.py b/main.py old mode 100644 new mode 100755 index 42f05c8..5f6872d --- a/main.py +++ b/main.py @@ -4,23 +4,22 @@ # file, You can obtain one at http://mozilla.org/MPL/2.0/. from mastodon import Mastodon -from getpass import getpass from os import path from bs4 import BeautifulSoup -import shutil, os, sqlite3, signal, sys +import shutil, os, sqlite3, signal, sys, json # import re -api_base_url = "https://botsin.space" scopes = ["read:statuses", "read:accounts", "read:follows", "write:statuses"] +cfg = json.load(open('config.json', 'r')) if not path.exists("clientcred.secret"): print("No clientcred.secret, registering application") - Mastodon.create_app("lynnesbian_mastodon_ebooks", api_base_url=api_base_url, to_file="clientcred.secret", scopes=scopes, website="https://github.com/Lynnesbian/mastodon-ebooks") + Mastodon.create_app("lynnesbian_mastodon_ebooks", api_base_url=cfg['site'], to_file="clientcred.secret", scopes=scopes, website="https://github.com/Lynnesbian/mastodon-ebooks") if not path.exists("usercred.secret"): print("No usercred.secret, registering application") - client = Mastodon(client_id="clientcred.secret", api_base_url=api_base_url) + client = Mastodon(client_id="clientcred.secret", api_base_url=cfg['site']) print("Visit this url:") print(client.auth_request_url(scopes=scopes)) client.log_in(code=input("Secret: "), to_file="usercred.secret", scopes=scopes) @@ -68,7 +67,10 @@ def parse_toot(toot): # next up: store this and patch markovify to take it # return {"text": text, "mentions": mentions, "links": links} # it's 4am though so we're not doing that now, but i still want the parser updates - return "\0".join(list(text)) + #todo: we split above and join now, which is dumb, but i don't wanna mess with the map code bc i don't understand it uwu + text = "\n".join(list(text)) + text = text.replace("'", "'") + return text def get_toots(client, id, since_id): i = 0 @@ -95,7 +97,7 @@ def get_toots(client, id, since_id): client = Mastodon( client_id="clientcred.secret", access_token="usercred.secret", - api_base_url=api_base_url) + api_base_url=cfg['site']) me = client.account_verify_credentials() following = client.account_following(me.id) diff --git a/reply.py b/reply.py index 762198e..a3f0f2b 100755 --- a/reply.py +++ b/reply.py @@ -4,15 +4,17 @@ # file, You can obtain one at http://mozilla.org/MPL/2.0/. import mastodon -import os, random, re +import os, random, re, json import create from bs4 import BeautifulSoup -api_base_url = "https://botsin.space" +cfg = json.load(open('config.json', 'r')) + +api_base_url = "https://knzk.me" client = mastodon.Mastodon( client_id="clientcred.secret", access_token="usercred.secret", - api_base_url=api_base_url) + api_base_url=cfg['site']) def extract_toot(toot): #copied from main.py, see there for comments