#config.json *MUST* contain the instance URL, the instance blacklist (for dead/broken instances), and the CW text. if they're not provided, we'll fall back to defaults.
c.execute("CREATE TABLE IF NOT EXISTS `toots` (id INT NOT NULL UNIQUE PRIMARY KEY, userid INT NOT NULL, uri VARCHAR NOT NULL, content VARCHAR NOT NULL) WITHOUT ROWID")
#this is a link formatted like "https://instan.ce/users/username", which is what we need
uri=link['href']
uri="{}/outbox?page=true".format(uri)
r=requests.get(uri,timeout=10)
j=r.json()
exceptException:
print("oopsy woopsy!! we made a fucky wucky!!!\n(we're probably rate limited, please hang up and try again)")
sys.exit(1)
pleroma=False
if'first'injandtype(j['first'])!=str:
print("Pleroma instance detected")
pleroma=True
j=j['first']
else:
print("Mastodon/Misskey instance detected")
uri="{}&min_id={}".format(uri,last_toot)
r=requests.get(uri)
j=r.json()
print("Downloading and saving toots",end='',flush=True)
done=False
try:
whilenotdoneandlen(j['orderedItems'])>0:
foroiinj['orderedItems']:
ifoi['type']!="Create":
continue#this isn't a toot/post/status/whatever, it's a boost or a follow or some other activitypub thing. ignore
# its a toost baby
content=oi['object']['content']
ifoi['object']['summary']!=None:
#don't download CW'd toots. if you want your bot to download and learn from CW'd toots, replace "continue" with "pass". (todo: add a config.json option for this)
continue
toot=extract_toot(content)
# print(toot)
try:
ifpleroma:
ifc.execute("SELECT COUNT(*) FROM toots WHERE id LIKE ?",(oi['object']['id'],)).fetchone()[0]>0:
#we've caught up to the notices we've already downloaded, so we can stop now
#you might be wondering, "lynne, what if the instance ratelimits you after 40 posts, and they've made 60 since main.py was last run? wouldn't the bot miss 20 posts and never be able to see them?" to which i reply, "it's called mstdn-ebooks not fediverse-ebooks. pleroma support is an afterthought"