Browse Source

Initial config and mastodon connectors

pull/90/head
kk6fut 2 years ago
parent
commit
0ee71ee2cc
  1. 9
      configs/mainconf.ini.example
  2. 40
      defMastodon.py

9
configs/mainconf.ini.example

@ -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

@ -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
Loading…
Cancel
Save