38 lines
801 B
Python
Executable File
38 lines
801 B
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
# import libs
|
|
from mastodon import Mastodon
|
|
import os
|
|
import random
|
|
|
|
# import config files and auth files
|
|
import config
|
|
import auth
|
|
|
|
# choose a random image
|
|
randomImageChoice = random.choice(os.listdir(config.picturePath))
|
|
randomImage = config.picturePath + randomImageChoice
|
|
|
|
# connect to the mastodon api
|
|
mastodon = Mastodon(
|
|
access_token = auth.token,
|
|
api_base_url = config.instance
|
|
)
|
|
|
|
print('sending image '+randomImage+'...')
|
|
|
|
# generate media dict
|
|
media = mastodon.media_post(randomImage, None, config.desc)
|
|
|
|
#print(media)
|
|
|
|
# post image as status
|
|
tootSent = mastodon.status_post(config.status, media_ids=media)
|
|
|
|
# clean up and make sure image not used again
|
|
os.rename(randomImage, config.usedPicturePath+randomImageChoice)
|
|
|
|
print('Sent!')
|
|
print(tootSent['url'])
|
|
|