#!/home/naiji/mastodon/maid-bot/venv/bin/python import requests import sys import random import os import os.path as op from mastodon import Mastodon from datetime import datetime # -------------------------------------------------- URL_FILE = "sources.dat" def main(): mastodon = Mastodon( access_token = 'token.dat', api_base_url = 'https://udongein.xyz/' ) with open(URL_FILE, 'r', encoding='utf-8') as file: data = file.readlines() pair = data[random.randint(0, len(data))] metadata = pair.split() print('\nsource:' + metadata[0] + '\nlink to attach:' + metadata[1]) img_data = requests.get(metadata[0]).content fformat = op.splitext(metadata[0])[1][1:] if (fformat == 'jpg'): fformat = 'jpeg' img_data = requests.get(metadata[0]).content #with open('temp_' + metadata[0], 'wb') as handler: # handler.write(img_data) fformat = op.splitext(metadata[0])[1][1:] if (fformat == 'jpg'): fformat = 'jpeg' media = mastodon.media_post(img_data, f'image/{fformat}') toot = f' :azrn_shiratsuyu_maid: \nSource: ' + metadata[1] mastodon.status_post(toot, media_ids=[media], visibility='unlisted', sensitive=False) if __name__ == '__main__': sys.exit(main())