commit a26b9d804c1fdbe77668038d2477d0c08c959a2b Author: Lynne Date: Sun Jan 19 21:13:46 2020 +1000 init commit diff --git a/dict.db b/dict.db new file mode 100644 index 0000000..3d3899e Binary files /dev/null and b/dict.db differ diff --git a/gen.py b/gen.py new file mode 100755 index 0000000..84f1b06 --- /dev/null +++ b/gen.py @@ -0,0 +1,37 @@ +#!/usr/bin/env python3 +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +from mastodon import Mastodon +import argparse, sys, traceback, random, sqlite3, re + +parser = argparse.ArgumentParser(description='Generate and post a toot.') +parser.add_argument('-s', '--simulate', dest='simulate', action='store_true', + help="Print the toot to stdout without posting it") + +args = parser.parse_args() + +client = Mastodon( + client_id="clientcred.secret", + access_token="usercred.secret", + api_base_url="https://botsin.space") + +db = sqlite3.connect("dict.db") +db.text_factory=str +c = db.cursor() +data = c.execute(r'SELECT word, definition FROM entries WHERE word LIKE "%ar%" AND wordtype LIKE "n."').fetchall() +dset = random.choice(data) +toot = "What's a pirate's favourite {}?\nA {}!".format( + re.search(r"^([^.]+)", dset[1]).group(1).replace("\n ", ""), dset[0].lower().replace("ar", "a" + ('r' * random.randint(3,10))) +) + +if not args.simulate: + try: + client.status_post(toot, visibility = 'unlisted') + except Exception as err: + toot = "Mistress @lynnesbian@fedi.lynnesbian.space, something has gone terribly" \ + + " wrong! While attempting to post a toot, I received the following" \ + + " error:\n" + "\n".join(traceback.format_tb(sys.exc_info()[2])) + client.status_post(toot, visibility = 'unlisted', spoiler_text = "Error!") +print(toot) diff --git a/main.py b/main.py new file mode 100755 index 0000000..2781ff1 --- /dev/null +++ b/main.py @@ -0,0 +1,20 @@ +#!/usr/bin/env python3 +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +from mastodon import Mastodon +from os import path + +scopes = ["read:statuses", "read:accounts", "read:follows", "write:statuses"] + +if not path.exists("clientcred.secret"): + print("No clientcred.secret, registering application") + Mastodon.create_app("piratebot", api_base_url="https://botsin.space", to_file="clientcred.secret", scopes=scopes, website="https://lynnesbian.space") + +if not path.exists("usercred.secret"): + print("No usercred.secret, registering application") + client = Mastodon(client_id="clientcred.secret", api_base_url="https://botsin.space") + print("Visit this url:") + print(client.auth_request_url(scopes=scopes)) + client.log_in(code=input("Secret: "), to_file="usercred.secret", scopes=scopes) diff --git a/run.sh b/run.sh new file mode 100755 index 0000000..5c7fbdf --- /dev/null +++ b/run.sh @@ -0,0 +1,4 @@ +#!/bin/sh +#cd /home/bots/mastodon-ebooks/ +#penos=$(python3 ./main.py > /dev/null) +python3 ./gen.py > /dev/null