1
0
Fork 0
mirror of https://github.com/Lynnesbian/FediBooks/ synced 2024-11-25 08:38:59 +00:00

seperated text generation and posting into their own functions

This commit is contained in:
Lynne Megido 2020-01-20 12:53:11 +10:00
parent 841098cc18
commit 898f2f7aae
Signed by: lynnesbian
GPG key ID: F0A184B5213D9F90

View file

@ -34,13 +34,7 @@ def extract_post(post):
text = text.rstrip("\n") # remove trailing newline(s)
return text
def make_post(args):
id = None
acct = None
if len(args) > 1:
id = args[1]
acct = args[3]
handle = args[0]
def generate_output(handle):
db = MySQLdb.connect(
host = cfg['db_host'],
user=cfg['db_user'],
@ -128,6 +122,19 @@ def make_post(args):
# also format handles without instances, e.g. @user instead of @user@instan.ce
post = re.sub(r"(?<!\S)@(\w+)", r"@{}\1".format(zws), post)
return post
def make_post(args):
id = None
acct = None
if len(args) > 1:
id = args[1]
acct = args[3]
handle = args[0]
post = generate_output(handle)
# print(post)
visibility = bot['post_privacy'] if len(args) == 1 else args[2]
visibilities = ['public', 'unlisted', 'private']
@ -141,6 +148,8 @@ def make_post(args):
# TODO: ehhhhhhhhh
post = post[:bot['length']]
# send toot!!
print(post)
return
try:
client.status_post(post, id, visibility = visibility, spoiler_text = bot['content_warning'])
except MastodonUnauthorizedError: