From 0ee71ee2ccc41a874d6a82c9aea6b96e0a94fa95 Mon Sep 17 00:00:00 2001 From: kk6fut Date: Wed, 14 Dec 2022 08:46:03 -0800 Subject: [PATCH 1/9] Initial config and mastodon connectors --- configs/mainconf.ini.example | 9 +++++++- defMastodon.py | 40 ++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 defMastodon.py diff --git a/configs/mainconf.ini.example b/configs/mainconf.ini.example index 114b869..bebdbc7 100644 --- a/configs/mainconf.ini.example +++ b/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 \ No newline at end of file +OPTION = ADSBX + +[MASTODON] +ENABLE = TRUE +ACCESS_TOKEN = mastodonaccesstoken +APP_URL = mastodonappurl +MAX_IMAGE_SIZE = maximagesizeformastodonserver + diff --git a/defMastodon.py b/defMastodon.py new file mode 100644 index 0000000..de6343d --- /dev/null +++ b/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 From 4963c8b15eb1b99fcbe449c8fc7b1aefc549afa5 Mon Sep 17 00:00:00 2001 From: kk6fut Date: Wed, 14 Dec 2022 08:49:05 -0800 Subject: [PATCH 2/9] Plug in Mastodon section --- planeClass.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/planeClass.py b/planeClass.py index 4b24edf..9baf884 100644 --- a/planeClass.py +++ b/planeClass.py @@ -463,6 +463,11 @@ class Plane: from defTelegram import sendTeleg photo = open(self.map_file_name, "rb") sendTeleg(photo, message, self.config) + #Mastodon + if self.config.has_section('MASTODON') and self.config.getboolean('MASTODON', 'ENABLE'): + from defMastodon import sendMastodon + sendMastodon(self.map_file_name, message, self.config) + #Discord if self.config.getboolean('DISCORD', 'ENABLE'): role_id = self.config.get('DISCORD', 'ROLE_ID') if self.config.has_option('DISCORD', 'ROLE_ID') and self.config.get('DISCORD', 'ROLE_ID').strip() != "" else None @@ -880,4 +885,4 @@ class Plane: print(time_since_ra) if time_since_ra.seconds >= 600: print(ra_type) - self.recent_ra_types.pop(ra_type) \ No newline at end of file + self.recent_ra_types.pop(ra_type) From f12b86facb74ef55a1f85f807019aeb1bfe3ee25 Mon Sep 17 00:00:00 2001 From: kk6fut Date: Wed, 14 Dec 2022 18:44:12 -0800 Subject: [PATCH 3/9] Needed additional account config (per-plane) --- configs/plane1.ini.example | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/configs/plane1.ini.example b/configs/plane1.ini.example index 5c2a8f1..ff3d03b 100644 --- a/configs/plane1.ini.example +++ b/configs/plane1.ini.example @@ -51,4 +51,11 @@ ACCESS_TOKEN = ENABLE = FALSE TITLE = Title Of Telegram message ROOM_ID = -100xxxxxxxxxx -BOT_TOKEN = xxxxxxxxxx:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \ No newline at end of file +BOT_TOKEN = xxxxxxxxxx:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx + +[MASTODON] +ENABLE = TRUE +ACCESS_TOKEN = mastodonaccesstoken +APP_URL = mastodonappurl +MAX_IMAGE_SIZE = maximagesize + From 0769cfe775b5bc03c345bba3cce726e0124ecebf Mon Sep 17 00:00:00 2001 From: kk6fut Date: Wed, 14 Dec 2022 19:57:22 -0800 Subject: [PATCH 4/9] Fix variable name in bot --- defMastodon.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/defMastodon.py b/defMastodon.py index de6343d..fd514e9 100644 --- a/defMastodon.py +++ b/defMastodon.py @@ -9,8 +9,8 @@ def sendMastodon(photo, message, config): 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) + mediaid = bot.media_post(photo, mime_type="image/jpeg") + sent = bot.status_post(message,None,mediaid,False, "Public") except Exception as err: print('err.args:') print(err.args) From 07b153538b2950146374236243b59ed14d73b351 Mon Sep 17 00:00:00 2001 From: kk6fut Date: Wed, 14 Dec 2022 20:19:50 -0800 Subject: [PATCH 5/9] Fix to get Mastodon connector working, tested. --- configs/plane1.ini.example | 1 - defMastodon.py | 7 +++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/configs/plane1.ini.example b/configs/plane1.ini.example index ff3d03b..00be1d0 100644 --- a/configs/plane1.ini.example +++ b/configs/plane1.ini.example @@ -57,5 +57,4 @@ BOT_TOKEN = xxxxxxxxxx:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ENABLE = TRUE ACCESS_TOKEN = mastodonaccesstoken APP_URL = mastodonappurl -MAX_IMAGE_SIZE = maximagesize diff --git a/defMastodon.py b/defMastodon.py index fd514e9..ecf5ae2 100644 --- a/defMastodon.py +++ b/defMastodon.py @@ -5,10 +5,9 @@ def sendMastodon(photo, message, config): while sent == False: try: bot = Mastodon( - access_token=config.get['MASTODON']['ACCESS_TOKEN'], - api_base_url=config.get['MASTODON']['APP_URL'] + 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 = bot.media_post(photo, mime_type="image/jpeg") sent = bot.status_post(message,None,mediaid,False, "Public") except Exception as err: @@ -17,7 +16,7 @@ def sendMastodon(photo, message, config): print(f"Unexpected {err=}, {type(err)=}") print("\nString err:\n"+str(err)) if retry_c > 4: - print('Telegram attempts exceeded. Message not sent.') + print('Mastodon attempts exceeded. Message not sent.') break elif str(err) == 'Unauthorized': print('Invalid Mastodon bot token, message not sent.') From 1e56b26b35f35390d14886ddaf75253a93fc1806 Mon Sep 17 00:00:00 2001 From: kk6fut Date: Wed, 14 Dec 2022 20:29:14 -0800 Subject: [PATCH 6/9] Fix missing prerequisites in install instructions --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index 1de6e6c..060da98 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,9 @@ pip install pipenv pipenv install ``` +### Install tabulate for table display +pip3 install tabulate + ### Install Selenium / ChromeDriver or setup Google Static Maps Selenium/ChromeDriver is used to take a screenshot of the plane on globe.adsbexchange.com. Or use Google Static Maps, which can cost money if overused(No tutorial use to get to a key). @@ -51,6 +54,10 @@ sudo apt-get install chromium ``` These output methods once installed can be configured in the planes config you create, using the example plane1.ini +### Install webdriver_manager, required for managing web browser + +pip3 install webdriver_manager + ### Install Screen to run in the background ```bash From f305541a17b3bfe824fadef0b48f4864af2e1967 Mon Sep 17 00:00:00 2001 From: Jack Sweeney Date: Thu, 22 Dec 2022 21:33:47 -0500 Subject: [PATCH 7/9] Update mainconf.ini.example The main config does need the Mastodon info --- configs/mainconf.ini.example | 7 ------- 1 file changed, 7 deletions(-) diff --git a/configs/mainconf.ini.example b/configs/mainconf.ini.example index bebdbc7..54133c7 100644 --- a/configs/mainconf.ini.example +++ b/configs/mainconf.ini.example @@ -62,10 +62,3 @@ CONSUMER_SECRET = cs #Map to create from Google Static Maps or screenshot global tar1090 from globe.adsbexchange.com #Enter GOOGLESTATICMAP or ADSBX OPTION = ADSBX - -[MASTODON] -ENABLE = TRUE -ACCESS_TOKEN = mastodonaccesstoken -APP_URL = mastodonappurl -MAX_IMAGE_SIZE = maximagesizeformastodonserver - From bba2eb75a16630a4856cb450c612a982700a2079 Mon Sep 17 00:00:00 2001 From: Jack Sweeney Date: Thu, 22 Dec 2022 21:36:08 -0500 Subject: [PATCH 8/9] Update README.md Pip dependencies are managed with Pipfile and pipenv --- README.md | 7 ------- 1 file changed, 7 deletions(-) diff --git a/README.md b/README.md index 060da98..1de6e6c 100644 --- a/README.md +++ b/README.md @@ -40,9 +40,6 @@ pip install pipenv pipenv install ``` -### Install tabulate for table display -pip3 install tabulate - ### Install Selenium / ChromeDriver or setup Google Static Maps Selenium/ChromeDriver is used to take a screenshot of the plane on globe.adsbexchange.com. Or use Google Static Maps, which can cost money if overused(No tutorial use to get to a key). @@ -54,10 +51,6 @@ sudo apt-get install chromium ``` These output methods once installed can be configured in the planes config you create, using the example plane1.ini -### Install webdriver_manager, required for managing web browser - -pip3 install webdriver_manager - ### Install Screen to run in the background ```bash From 92a6f5808df7e1d048b958bc811231b0a48e3efd Mon Sep 17 00:00:00 2001 From: Jack Sweeney Date: Thu, 22 Dec 2022 21:38:36 -0500 Subject: [PATCH 9/9] Update planeClass.py Adds Mastodon circling messages --- planeClass.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/planeClass.py b/planeClass.py index 9baf884..ca9122c 100644 --- a/planeClass.py +++ b/planeClass.py @@ -821,6 +821,10 @@ class Plane: if self.config.has_option('META', 'ENABLE') and self.config.getboolean('META', 'ENABLE'): from meta_toolkit import post_to_meta_both post_to_meta_both(self.config.get("META", "FB_PAGE_ID"), self.config.get("META", "IG_USER_ID"), self.map_file_name, message, self.config.get("META", "ACCESS_TOKEN")) + #Mastodon + if self.config.has_section('MASTODON') and self.config.getboolean('MASTODON', 'ENABLE'): + from defMastodon import sendMastodon + sendMastodon(self.map_file_name, message, self.config) self.circle_history['triggered'] = True elif abs(total_change) <= 360 and self.circle_history["triggered"]: print("No Longer Circling, trigger cleared")