MLP Trixie Lulamoon bot for Mastodon
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

69 lines
2.2 KiB

import sys
import random
import datetime
import os.path as op
from pprint import pprint
import requests
from mastodon import Mastodon
# --------------------------------------------------
def main():
mastodon = Mastodon(
access_token = 'token.dat',
api_base_url = 'https://social.inex.rocks/'
)
if op.isfile('screens.dat'):
with open('screens.dat', 'r', encoding='utf-8') as file:
data = file.readlines()
else:
ttime = str(datetime.datetime.now().time())
url = 'https://vignette.wikia.nocookie.net/mlp/images/c/c7/Trixie_sighing_sadly_S6E6.png'
print(ttime, ': screens.dat is missing! Please, generate new sources with :/parses.py!')
try:
media = mastodon.media_post(requests.get(url).content, f'image/png')
toot = f'My sources are missing! Please, contanct @NaiJi!\n:trixiesweating::trixiesweating::trixiesweating:'
mastodon.status_post(toot, media_ids=[media], visibility='unlisted')
except KeyboardInterrupt:
sys.exit(1)
except:
ttime = str(datetime.datetime.now().time())
print(ttime, ': Network error while posting a screenshot without the source file')
return
# Emojis for each of her toot
if op.isfile('emojis.dat'):
with open('emojis.dat', 'r', encoding='utf-8') as file:
emojis = file.readlines()
else:
ttime = str(datetime.datetime.now().time())
print(ttime, ': Emojis disappeared!')
emojis = [ ':trixiehappy:' ]
rnum = random.randint(0, (len(data) - 2) / 2)
url = data[rnum * 2].strip()
status = data[rnum * 2 + 1].strip()
fformat = op.splitext(url)[1][1:]
emoji = emojis[random.randint(0, len(emojis) - 1)]
try:
media = mastodon.media_post(requests.get(url).content, f'image/{fformat}')
toot = f'{status}\n#MLP #MLPFIM #MLPTrixie {emoji}'
mastodon.status_post(toot, media_ids=[media], visibility='unlisted')
except KeyboardInterrupt:
sys.exit(1)
except:
ttime = str(datetime.datetime.now().time())
print(ttime, ': Network error while posting a screenshot!')
if __name__ == '__main__':
sys.exit(main())