sanelkukic / oibot

OIBot is a XMPP chatbot that allows for messages posted on NWWS-OI to be forwarded to a Discord webhook

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

oibot

An XMPP chat bot that connects to NWWS-OI and can forward messages to a Discord webhook.

I made this because I looked around the internet and couldn't find a single free-to-use or open-source XMPP client that was able to parse the contents of NWWS-OI messages and display them. There used to be clients that worked but they no longer work so I tasked myself with making my own client.

Inspired by jbuitt/nwws-python-client.

How does it work?

Using slixmpp, it connects to the NWWS-OI XMPP server and listens for messages from WFOs.

You can configure which WFOs you want to trigger the script in the configuration file, detailed below. Or, you can have it go off for every single message posted on NWWS-OI (not recommended in a production environment but useful for testing the script)

Completely contained in one single Python file, too.

How do I use it?

For starters, you need to have credentials to access NWWS-OI. You can obtain these credentials on the National Weather Service's webpage

Once you have obtained your credentials, you need to create a .json file that looks like the following. A blank, example configuration file is included with the Python script and in this repository.

{
  "username": "<INSERT YOUR NWWS-OI USERNAME HERE>",
  "password": "<INSERT YOUR NWWS-OI PASSWORD HERE>",
  "server": "nwws-oi.weather.gov",
  "port": 5222,
  "use_ssl": false,
  "resource": "nwws",
  "wfo_offices": [
    "<SPECIFY THE ID OF EACH WFO THAT YOU WANT TO RECEIVE MESSAGES FROM>"
  ],
  "discord_webhook": "<INSERT THE URL OF YOUR DISCORD WEBHOOK HERE>",
  "enable_win10_notifications": false
}

If you wish to receive messages from all WFOs, put the word "every" in your wfo_offices configuration, such that it looks like this:

"wfo_offices": [
    "every"
]

Now, simply fill in the fields that have a placeholder in them, save the file, and run the following commands in your terminal:

$ pip install -r requirements.txt
$ python oibot.py <path to your config file here>

You can also run the script with the -g or --gen-config argument to generate a template configuration file akin to the one displayed above.

Once you've done that, you should see the program start up, print some basic information, and if all goes well you should see the federal government warning message that everyone who logs in to NWWS-OI sees:

**WARNING**WARNING**WARNING**WARNING**WARNING**WARNING**WARNING**WARNING**

This is a United States Federal Government computer system, which may be
accessed and used only for official Government business by authorized
personnel.  Unauthorized access or use of this computer system may
subject violators to criminal, civil, and/or administrative action.

All information on this computer system may be intercepted, recorded,
read, copied, and disclosed by and to authorized personnel for official
purposes, including criminal investigations. Access or use of this
computer system by any person whether authorized or unauthorized,
CONSTITUTES CONSENT to these terms.

**WARNING**WARNING**WARNING**WARNING**WARNING**WARNING**WARNING**WARNING**

Once you see this message, you know you're connected. All you have to do now is sit back and wait. Based on your configuration, the program will send messages to the Discord webhook you specified.

Enabling toast notifications on Windows 10

If you are running this script on Windows 10, you can install an additional package and change a setting in your configuration file to enable toast notifications every time a new message is posted to NWWS-OI. To do this, follow these steps.

  1. Run pip install -r requirements-windows.txt in your terminal.
  2. Open your configuration file and change the value for enable_win10_notifications from false to true, then save your configuration file.
  3. Run the program and specify the path to your configuration file!

It really is that easy :D

Validating your configuration file

If you believe your configuration file is invalid, you can use OIBot's built-in configuration validation tool to check. Simply run the following commands in your terminal:

$ python oibot.py <path to your config here> --validate

For example, if your configuration file is located in the same directory as the Python script, and it's named config.json, you would run:

$ python oibot.py config.json --validate

OIBot will try to open the configuration file and validate it. If the validation passes, you'll see the following output:

[i] Configuration file is valid

However, if the configuration is not valid, you will see either an error message detailing what setting is invalid in the configuration or the following message:

[x] Failed to validate that configuration file

Is this free to use? Do I need to buy a license?

Yes, and no. This is completely free-to-use by anyone who is authorized to access NWWS-OI. You do not need to pay me a single penny to use this, however, I would greatly appreciate it if you sponsor me on GitHub or bought me a coffee.

If you paid to obtain access to this software, you have been SCAMMED and you should contact your financial institution to report the fraud as soon as possible. You may also want to report the fraud to the Federal Trade Commission and/or file a report with your local police department. If you believe your identity has been stolen, visit the Federal Trade Commission's Identity Theft website to file a report.

License

This program is licensed under the terms and conditions of the MIT License. The full text of the license can be found in the LICENSE.txt file.

About

OIBot is a XMPP chatbot that allows for messages posted on NWWS-OI to be forwarded to a Discord webhook

License:MIT License


Languages

Language:Python 100.0%