Skip to content

Commit

Permalink
Merge pull request #2 from joergschultzelutter/apprise
Browse files Browse the repository at this point in the history
Apprise
  • Loading branch information
joergschultzelutter authored Apr 23, 2024
2 parents 5dfee49 + afd0c98 commit 64497e8
Show file tree
Hide file tree
Showing 22 changed files with 976 additions and 980 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,5 @@ venv
mowas-pwb.cfg
/src/modules/gefahr06.txt
*.png
full_msg.yml
short_msg.yml
10 changes: 1 addition & 9 deletions docs/ADDITIONAL_INFO.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,8 @@ The potential side effect for this constraint is that if you start the program a

- In order to match with a given watch area, the user's coordinates (```mowas_watch_areas``` from the program config file) have either to be _inside_ of the given polygon or _intersect_ with it.
- Currently, there is no option that enables the user to specify and additional proximity to that polygon ("Polygon plus 10km distance")
- This program uses native MOWAS data. All warning messages are in German. However, you can activate an auto-translation for these messages (via [deepl](www.deepl.com)). The translated content will be displayed _in_ _addition_ to the original German text (Email, Telegram) which should make it easier for German citizens to help you in case of emergencies. Due to the lack of UTF-8 support, the DAPNET part of the program will only support English for translated content and will ignore translations in other languages.
- Obviously, the current version of this program does not scale and cannot support multiple user's needs with just one program instance - you can specify only _one_ DAPNET/Telegram/Email target account.
- This program uses native MOWAS data. All warning messages are in German. However, you can activate an auto-translation for these messages (via [deepl](www.deepl.com)). The translated content will be displayed _in_ _addition_ to the original German text (Email, Telegram) which should make it easier for German citizens to help you in case of emergencies. Due to the lack of UTF-8 support, SMS messages will be rendered as plain ASCII.
- As the MOWAS APIs are not officially available to end users, government authorities might either terminate the services without notice and / or change the format settings of the services that are currently exposed (but not officially available to end users)
- Although all MOWAS messages do contain warncell references (which allows the program's DAPNET part to use the region's abbreviated region description), certain messages do contain invalid warncell identifiers. If such an case is encountered, MOWAS will use the (lenghty) original regional description instead. For DAPNET messages which are limited to 80 characters per message, the program will try to shorten that description by removing some clutter from that message.
- If you want to use this program for a different country's warning system:
- remove the call for retrieving the 'warncell' information - this one is only relevant to German users
- replace the MOWAS module with your country's native warn system parser code
- change the DAPNET message group setting from ``dl-all`` (Germany) to your locale's transponder group.
- There is no message dupe check _on a content level_; if the same message is present in more than one MOWAS category and ``mowas-pwb`` deemed this message to be valid for your coordinates and program parameters' selection, you may receive that message more than once - unless the MOWAS government feed provides the message with the same unique identifier.
- All MOWAS messages contain a LOT of text, meaning that DAPNET users will likely receive a lot of messages in case an alarm is triggered (keep in mind that DAPNET is limited to 80 chars per messages). Unfortunately, abbreviated warning messages are not available.
- You may want to set up you Telegram bot as a private bot, thus preventing other Telegram users from discovering and using it. Good instructions on how to do this can be found here: [https://sarafian.github.io/low-code/2020/03/24/create-private-telegram-chatbot.html](https://sarafian.github.io/low-code/2020/03/24/create-private-telegram-chatbot.html).

Have a look at the [legal information](LEGAL.md)
65 changes: 39 additions & 26 deletions docs/COMMANDS.md

Large diffs are not rendered by default.

45 changes: 22 additions & 23 deletions docs/INSTALLATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

## Requirements

- DAPNET, Telegram and/or email account access credentials are required.
- DAPNET: [https://hampager.de/dokuwiki/doku.php](https://hampager.de/dokuwiki/doku.php)
- Telegram: create your own bot. See e.g. [https://sarafian.github.io/low-code/2020/03/24/create-private-telegram-chatbot.html](https://sarafian.github.io/low-code/2020/03/24/create-private-telegram-chatbot.html)
- For APRS tracking (``follow-the-ham`` option), a valid aprs.fi access key is required. Get it here: [https://aprs.fi/page/api](https://aprs.fi/page/api)
- For automated translations, a free deepl.com API license key is required which can be obtained here: [https://www.deepl.com/pro-api?cta=header-pro-api](https://www.deepl.com/pro-api?cta=header-pro-api)
- In case you intend to use the Google PaLm or OpenAI APIs for text summarization, you need to provide the necessary API keys for the ``-text-summarizer`` command option. Both ``internal`` and ``generic`` options do not use API keys.

## General instructions

Expand All @@ -28,12 +26,18 @@
user@phost:~/mowas-pwb/src $ mv mowas-pwb.cfg.TEMPLATE mowas-pwb.cfg
```

- edit the Apprise yml config file and add your messenger(s). Note: full-text messages and SMS messages should use separate config files

```bash
user@phost:~/mowas-pwb/src $ vi apprise_demo_template.yml
```

- Start the program. In case all libraries have been installed, you should see the following:

```bash
user@phost:~/mowas-pwb/src $ python mowas-pwb.py
2021-12-20 21:39:00,719 mowas-pwb -INFO- Startup ...
2021-12-20 21:39:00,725 mowas-pwb -INFO- No target credentials (DAPNET, Email or Telegram) configured or no messaging destinations specified; exiting ...
2021-12-20 21:39:00,725 mowas-pwb -INFO- No messenger target credentials configured or no messaging destinations specified; exiting ...
```

When you can see this message, all required libraries have been installed. You are now required to update the program configuration file.
Expand All @@ -43,13 +47,12 @@ When you can see this message, all required libraries have been installed. You a
``mowas-pwb`` comes with a program config file which mainly contains API keys. In order to use the program, you need to configure this file.

- ``aprsdotfi_api_key`` is the aprs.fi access key that is used if you tell the program to use the ``follow-the-ham`` option
- ``dapnet_login_callsign`` and ``dapnet_login_passcode`` are required for sending data to DAPNET
- ``mowas_watch_areas`` defines your static watch areas. ``mowas-pwb`` will check these areas and if there is a match, it might forward you that warning message.
- ``telegram_bot_token`` defines the Telegram bot which will deliver potential warning messages to you.
- ``smtpimap_email_address``, ``smtpimap_email_password`` ``smtpimap_server_address`` and ``smtpimap_server_port`` are required for sending data from this email account to the user
-``imap_server_address``, ``imap_server_port`` ``imap_mailbox_name`` and ``imap_mail_retention_max_days`` need to be properly populated if ``mowas-pwb`` is supposed to clean up your mail account's "Sent" folder after x days.
- ``imap_server_address``, ``imap_server_port`` ``imap_mailbox_name`` and ``imap_mail_retention_max_days`` need to be properly populated if ``mowas-pwb`` is supposed to clean up your mail account's "Sent" folder after x days.
- ``mowas_active_categories`` defines the number of MOWAS categories which will be monitored by ``mowas-pwb``. By default, this setting contains all available MOWAS categories.
- ``deepldotcom_api_key`` needs to be populated with a deepl.com API key in case you intend to use the program's auto-translation option
- ``openai_api_key`` and ``palm_api_key`` need to be populated in case you intend to use the Opeen AI / Google PaLm APIs for text summary purposes.

A variable with the value of

Expand All @@ -76,20 +79,11 @@ When activated, the garbage collector will delete ALL of your mails in your 'Sen
# API key NOT_CONFIGURED disable aprs.fi access
aprsdotfi_api_key = NOT_CONFIGURED

# DAPNET access credentials
# Callsign NOT_CONFIGURED disables DAPNET access
dapnet_login_callsign = NOT_CONFIGURED
dapnet_login_passcode = -1

# Lat / Lon coordinates that we intend to monitor
# Format: lat1,lon1<space>lat2,lon2<space>.....latn,lonn
# Example: 51.838879,8.32678 51.829722,9.448333
mowas_watch_areas = 51.838879,8.32678 51.829722,9.448333

# Telegram bot token - this is the bot that will send out the message
# NOT_CONFIGURED disables Telegram access
telegram_bot_token = NOT_CONFIGURED

# SMTP / IMAP shared Credentials
# Providers like GMail require you to set an app-specific password
# (see https://myaccount.google.com/apppasswords)
Expand Down Expand Up @@ -134,23 +128,28 @@ mowas_active_categories = TEMPEST,FLOOD,FLOOD_OLD,WILDFIRE,EARTHQUAKE,DISASTERS
# You can register for a free API access key here:
# https://www.deepl.com/pro-api?cta=header-pro-api
deepldotcom_api_key = NOT_CONFIGURED

# OpenAI ChatGPT access key. Required if you want mowas-pwb to send messages
# via an abbreviated Apprise message config file with text summarizer
# option "openai", otherwise optional
openai_api_key = NOT_CONFIGURED

# OpenAI ChatGPT access key. Required if you want mowas-pwb to send messages
# via an abbreviated Apprise message config file with text summarizer
# option "palm", otherwise optional
palm_api_key = NOT_CONFIGURED
```

Apply the following changes to the file:

- __DAPNET__: Specify the __sender's__ user and password if you have one.
- __Telegram__:
- Specify the __sender's__ bot's access token (via ``The Botfather`` bot).
- Note that in order to permit the new bot to send data to your destination account, you __must__ first initiate a one-time chat between your Telegram target account and that bot - or the program will not be able to send messages to that account. This is a one-time manual setup.
- Just select the bot of yours in Telegram, click the __Start__ button and you're good to go. This is a Telegram security setting which ```mowas-pwb``` cannot bypass.
- If you don't establish the initial connection or stop the bot, sending messages to Telegram will fail and these failures will be noted in the program's log file.
- __Email__: specify the __sender's__ user/password
- If you want to use the ``follow-the-ham`` program option, populate the program's aprs.fi access key
- Ultimately, you need to specify the coordinates that you want to monitor. Each coordinate tuple is separated by a 'space' character. There is no limit in how many points you can specify.
- A configuration entry of ``mowas_watch_areas = 51.838879,8.32678 51.829722,9.448333`` would result in two coordinates that are going to be monitored independently from each other:
- C1: ``lat = 51.838879``, ``lon = 8.32678``
- C2: ``lat = 51.829722``, ``lon = 9.448333``
- Specify which categories ``mowas-pwb`` is supposed to monitor. Valid values: ``TEMPEST``,``FLOOD``,``FLOOD_OLD``,``WILDFIRE``,``EARTHQUAKE``,``DISASTER``. Default = all categories; at least one category needs to be specified.
- Finally, run the program. Specify a DAPNET ham radio call sign and/or a numeric Telegram user ID as targets. For your first run, I recommend using the ``generate_test_message`` program option - this will simply trigger a test message to DAPNET/Telegram/Email, thus allowing you to tell whether your program configuration is ok.
- ``openai_api_key`` and ``palm_api_key`` need to be populated in case you intend to use the Opeen AI / Google PaLm APIs for text summary purposes.
- Finally, run the program. Specify an email address and/or Apprise YML file as targets. For your first run, I recommend using the ``generate_test_message`` program option - this will simply trigger a test message, thus allowing you to tell whether your program configuration is ok.

Now have a look at the [program's command line parameters](COMMANDS.md)
5 changes: 2 additions & 3 deletions docs/LEGAL.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ In reference to the European Union's GDPR regulations and other legal rules and

- Although official government warning message feeds are consumed by this program, ``mowas-pwb`` itself is not an official Government warning app. __If it breaks, you get to keep both pieces.__ Even though its purpose is to alert you during hazardous situations, don't rely on ``mowas-pwb``'s availability and content validity during a life-and-death situation as sole source of information. When in doubt, always consult additional sources of information such as TV, radio & cell broadcasts and the Internet.

- Both DAPNET messaging option or the ``follow-the-ham`` aprs.fi tracking option __require you to be a licensed ham radio operator__. If you run this program in Telegram-or-Email-only mode, no ham radio license is required, though.
- Usage of the ``follow-the-ham`` aprs.fi tracking option __requires you to be a licensed ham radio operator__.

- In case the ``follow-the-ham`` option is used: The user's position information (as well as other APRS user's position data) which is used by this program is acquired from freely accessible data sources such as aprs.fi et al. These data sources gather APRS information from ham radio users who did decide to have their position information actively submitted to the APRS network. Any of these information sources can already be used for a various user's position inquiry.

- If you intend to host your own instance of ``mowas-pwb``, you need to provide API access keys to the following services:
- sender's email and password and/or
- telegram.org and/or
- DAPNET / hampager.de. __Requires a valid ham radio license.__
- Apprise messenger configuration(s)
- optional: aprs.fi access key. __Requires a valid ham radio license.__

If you use this program, then you agree to these terms and conditions. Thank you.
7 changes: 5 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
expiringdict>=1.2.1
numpy>=1.21.2
python-telegram-bot>=13.7
Shapely>=1.7.1
requests>=2.26.0
Unidecode>=1.3.2
APScheduler>=3.6.3
py-staticmaps>=0.4.0
git+https://github.com/flopp/py-staticmaps#egg-py-staticmaps
deepl>=1.3.1
geopy>=2.2.0
maidenhead>=1.6.0
utm>=0.7.0
bert-extractive-summarizer>=0.10.1
openai
google.generativeai
apprise>=1.7.1
8 changes: 8 additions & 0 deletions src/apprise_demo_template.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Format description: see https://github.com/caronc/apprise/wiki/config_yaml

version: 1

urls:
# One-liner (no colon at the end); just the url as you'd expect it:
- tgram://123456789:abcdefg_hijklmnop/12315544/

137 changes: 0 additions & 137 deletions src/dapnet.py

This file was deleted.

Loading

0 comments on commit 64497e8

Please sign in to comment.