2019-12-30 16:55:44 +00:00
|
|
|
#!/usr/bin/env python3
|
2019-12-30 16:49:32 +00:00
|
|
|
|
2019-12-30 17:08:03 +00:00
|
|
|
# import libs
|
2019-12-30 16:55:44 +00:00
|
|
|
from mastodon import Mastodon
|
|
|
|
import os
|
|
|
|
import random
|
2019-12-30 16:49:32 +00:00
|
|
|
|
2019-12-30 17:08:03 +00:00
|
|
|
# import config files and auth files
|
2019-12-30 16:55:44 +00:00
|
|
|
import config
|
2019-12-30 16:49:32 +00:00
|
|
|
import auth
|
|
|
|
|
2019-12-30 17:08:03 +00:00
|
|
|
# choose a random image
|
2019-12-30 21:11:34 +00:00
|
|
|
randomImageChoice = random.choice(os.listdir(config.picturePath))
|
|
|
|
randomImage = config.picturePath + randomImageChoice
|
2019-12-30 16:55:44 +00:00
|
|
|
|
2019-12-30 17:08:03 +00:00
|
|
|
# connect to the mastodon api
|
2019-12-30 16:49:32 +00:00
|
|
|
mastodon = Mastodon(
|
|
|
|
access_token = auth.token,
|
2019-12-30 16:55:44 +00:00
|
|
|
api_base_url = config.instance
|
2019-12-30 16:49:32 +00:00
|
|
|
)
|
|
|
|
|
2019-12-30 17:04:25 +00:00
|
|
|
print('sending image '+randomImage+'...')
|
|
|
|
|
2019-12-30 17:08:03 +00:00
|
|
|
# generate media dict
|
2019-12-30 17:04:25 +00:00
|
|
|
media = mastodon.media_post(randomImage, None, config.desc)
|
|
|
|
|
2019-12-30 17:08:03 +00:00
|
|
|
#print(media)
|
|
|
|
|
|
|
|
# post image as status
|
2019-12-30 19:19:39 +00:00
|
|
|
tootSent = mastodon.status_post(config.status, media_ids=media)
|
2019-12-30 17:08:03 +00:00
|
|
|
|
2019-12-30 21:11:34 +00:00
|
|
|
# clean up and make sure image not used again
|
|
|
|
os.rename(randomImage, config.usedPicturePath+randomImageChoice)
|
|
|
|
|
2019-12-30 17:08:03 +00:00
|
|
|
print('Sent!')
|
2019-12-30 19:19:39 +00:00
|
|
|
print(tootSent['url'])
|
2019-12-30 17:04:25 +00:00
|
|
|
|