init commit

This commit is contained in:
Lynne Megido 2020-01-19 21:13:46 +10:00
commit a26b9d804c
Signed by: lynnesbian
GPG Key ID: F0A184B5213D9F90
4 changed files with 61 additions and 0 deletions

BIN
dict.db Normal file

Binary file not shown.

37
gen.py Executable file
View File

@ -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)

20
main.py Executable file
View File

@ -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)

4
run.sh Executable file
View File

@ -0,0 +1,4 @@
#!/bin/sh
#cd /home/bots/mastodon-ebooks/
#penos=$(python3 ./main.py > /dev/null)
python3 ./gen.py > /dev/null