Initial config and mastodon connectors

This commit is contained in:
kk6fut 2022-12-14 08:46:03 -08:00
parent 64efa26199
commit 0ee71ee2cc
2 changed files with 48 additions and 1 deletions

View File

@ -61,4 +61,11 @@ CONSUMER_SECRET = cs
[MAP]
#Map to create from Google Static Maps or screenshot global tar1090 from globe.adsbexchange.com
#Enter GOOGLESTATICMAP or ADSBX
OPTION = ADSBX
OPTION = ADSBX
[MASTODON]
ENABLE = TRUE
ACCESS_TOKEN = mastodonaccesstoken
APP_URL = mastodonappurl
MAX_IMAGE_SIZE = maximagesizeformastodonserver

40
defMastodon.py Normal file
View File

@ -0,0 +1,40 @@
def sendMastodon(photo, message, config):
from mastodon import Mastodon
sent = False
retry_c = 0
while sent == False:
try:
bot = Mastodon(
access_token=config.get['MASTODON']['ACCESS_TOKEN'],
api_base_url=config.get['MASTODON']['APP_URL']
)
#todo: add photo/image processing here, Mastodon has strict image sizing requirements
mediaid = mastodonBot.media_post(photo, mime_type="image/jpeg")
sent = mastodonBot.status_post(message,None,mediaid,False, feedvisibility)
except Exception as err:
print('err.args:')
print(err.args)
print(f"Unexpected {err=}, {type(err)=}")
print("\nString err:\n"+str(err))
if retry_c > 4:
print('Telegram attempts exceeded. Message not sent.')
break
elif str(err) == 'Unauthorized':
print('Invalid Mastodon bot token, message not sent.')
break
elif str(err) == 'Timed out':
retry_c += 1
print('Mastodon timeout count: '+str(retry_c))
pass
elif str(err)[:35] == '[Errno 2] No such file or directory':
print('Mastodon module couldn\'t find an image to send.')
break
elif str(err) == 'Media_caption_too_long':
print('Mastodon image caption lenght exceeds 1024 characters. Message not send.')
break
else:
print('[X] Unknown error. Message not sent.')
break
else:
print("Mastodon message successfully sent.")
return sent