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

less log spam

This commit is contained in:
Lynne Megido 2020-01-20 12:18:17 +10:00
parent 6cfa9ef35f
commit 9830eeda6b
Signed by: lynnesbian
GPG key ID: F0A184B5213D9F90

View file

@ -47,11 +47,11 @@ def make_post(args):
passwd=cfg['db_pass'], passwd=cfg['db_pass'],
db=cfg['db_name'] db=cfg['db_name']
) )
print("Generating post for {}".format(handle)) # print("Generating post for {}".format(handle))
dc = db.cursor(MySQLdb.cursors.DictCursor) dc = db.cursor(MySQLdb.cursors.DictCursor)
c = db.cursor() c = db.cursor()
dc.execute(""" dc.execute("""
SELECT SELECT
learn_from_cw, learn_from_cw,
length, length,
fake_mentions, fake_mentions,
@ -64,7 +64,7 @@ def make_post(args):
FROM FROM
bots, credentials bots, credentials
WHERE WHERE
bots.handle = %s bots.handle = %s
AND bots.credentials_id = credentials.id AND bots.credentials_id = credentials.id
""", (handle,)) """, (handle,))
@ -92,7 +92,7 @@ def make_post(args):
# 4. join the list into a string separated by newlines # 4. join the list into a string separated by newlines
posts = "\n".join(list(sum(c.fetchall(), ()))) posts = "\n".join(list(sum(c.fetchall(), ())))
if len(posts) == 0: if len(posts) == 0:
print("No posts to learn from.") print("{} - No posts to learn from.".format(handle))
return return
if bot['fake_mentions'] == 'never': if bot['fake_mentions'] == 'never':
@ -124,11 +124,11 @@ def make_post(args):
if bot['fake_mentions_full']: if bot['fake_mentions_full']:
post = re.sub(r"@(\w+)@([\w.]+)", r"@{}\1@{}\2".format(zws, zws), post) post = re.sub(r"@(\w+)@([\w.]+)", r"@{}\1@{}\2".format(zws, zws), post)
else: else:
post = re.sub(r"@(\w+)@([\w.]+)", r"@{}\1".format(zws), post) post = re.sub(r"@(\w+)@([\w.]+)", r"@{}\1".format(zws), post)
# also format handles without instances, e.g. @user instead of @user@instan.ce # also format handles without instances, e.g. @user instead of @user@instan.ce
post = re.sub(r"(?<!\S)@(\w+)", r"@{}\1".format(zws), post) post = re.sub(r"(?<!\S)@(\w+)", r"@{}\1".format(zws), post)
print(post) # print(post)
visibility = bot['post_privacy'] if len(args) == 1 else args[2] visibility = bot['post_privacy'] if len(args) == 1 else args[2]
visibilities = ['public', 'unlisted', 'private'] visibilities = ['public', 'unlisted', 'private']
if visibilities.index(visibility) < visibilities.index(bot['post_privacy']): if visibilities.index(visibility) < visibilities.index(bot['post_privacy']):
@ -138,14 +138,15 @@ def make_post(args):
post = "{} {}".format(acct, post) post = "{} {}".format(acct, post)
# ensure post isn't longer than bot['length'] # ensure post isn't longer than bot['length']
post = post[:bot['length']] # TODO: ehhhhhhhhh
post = post[:bot['length']]
# send toot!! # send toot!!
try: try:
client.status_post(post, id, visibility = visibility, spoiler_text = bot['content_warning']) client.status_post(post, id, visibility = visibility, spoiler_text = bot['content_warning'])
except MastodonUnauthorizedError: except MastodonUnauthorizedError:
# user has revoked the token given to the bot # user has revoked the token given to the bot
# this needs to be dealt with properly later on, but for now, we'll just disable the bot # this needs to be dealt with properly later on, but for now, we'll just disable the bot
c.execute("UPDATE bots SET enabled = FALSE WHERE handle = %s", (handle,)) c.execute("UPDATE bots SET enabled = FALSE WHERE handle = %s", (handle,))
if id == None: if id == None:
# this wasn't a reply, it was a regular post, so update the last post date # this wasn't a reply, it was a regular post, so update the last post date