fixed a silly but rather bad bug\ni'm pretty sure i'm gonna stop working on fedibooks, and everything else i do relating to fedi. writing complex webapps to (rather poorly) interface with decentralised, half-standardised social networking platforms really isn't for me, and much of this code is honestly pretty awful. i have no idea why i did some of this stuff - for example, writing an object to interface with the outbox json would have been a LOT cleaner than what i'm currently doing. fedibooks really doesn't work well at all, and its biggest flaw is, of course, the fact that it can't interact with any instances using authenticated fetch. while i may fix minor bugs from time to time, i can pretty much guarantee that one's never getting fixed. i'm not shutting down fedibooks.com or anything like that - and if i ever do, i'll give advance warning - but don't expect any new features here, or in mstdn-ebooks, OCRbot, et al. but hey, at least it's fixed now.

This commit is contained in:
Lynne Megido 2020-05-27 19:39:15 +10:00
parent d9d7f751c6
commit 33b72d8e4c
Signed by: lynnesbian
GPG Key ID: F0A184B5213D9F90

View File

@ -88,7 +88,7 @@ def generate_output(handle):
posts = "\n".join(list(sum(c.fetchall(), ())))
if len(posts) == 0:
print("{} - No posts to learn from.".format(handle))
return
return bot, None
if bot['fake_mentions'] == 'never':
# remove all mentions from the training data before the markov model sees it
@ -99,8 +99,8 @@ def generate_output(handle):
post = None
# even with such a high tries value for markovify, it still sometimes returns none.
# so we implement our own tries function as well, and try ten times.
while post is None and tries < 10:
# so we implement our own tries function as well, and try five times.
while post is None and tries < 5:
post = model.make_short_sentence(bot['length'], tries = 1000)
tries += 1
@ -138,6 +138,10 @@ def make_post(args):
bot, post = generate_output(handle)
# post will be None if there's no posts for the bot to learn from.
# in such a case, we should just exit without doing anything.
if post == None: return
client = Mastodon(
client_id = bot['client_id'],
client_secret = bot['client_secret'],
@ -199,9 +203,9 @@ def get_key():
key['private'] = privkey.exportKey('PEM').decode('utf-8')
key['public'] = privkey.publickey().exportKey('PEM').decode('utf-8')
dc.execute("INSERT INTO http_auth_key (private, public) VALUES (%s, %s)", (key['private'], key['public']))
dc.close()
db.commit()
@ -243,4 +247,4 @@ def signed_get(url, timeout = 10, additional_headers = {}, request_json = True):
r = requests.Request('GET', url, headers)
return r.headers
# return requests.get(url, timeout = timeout)
# return requests.get(url, timeout = timeout)