This project is a comprehensive weather data analysis system that combines a Streamlit web dashboard for visualization, a CLI tool (Meteorix) for data management, and a Discord bot for remote CLI operations. It focuses on analyzing Hurricane Milton wind patterns and provides interactive tools across multiple interfaces.
- Setup Instructions
- Development Setup
- Web App Operations
- CLI Operations
- Discord Bot Operations
- Project Structure
-
Clone the repository and navigate to project folder:
git clone https://github.com/Sang-Buster/weather-dashboard cd weather-dashboard
-
Install uv first:
# macOS/Linux curl -LsSf https://astral.sh/uv/install.sh | sh
# Windows powershell -c "irm https://astral.sh/uv/install.ps1 | iex"
-
Create a virtual environment at
/weather-dashboard/.venv/
:uv venv --python 3.12.1
-
Activate the virtual environment:
# macOS/Linux source .venv/bin/activate
# Windows .venv\Scripts\activate
-
Install the required packages:
uv pip install -r requirements.txt
-
Install pre-commit:
uv pip install pre-commit
Pre-commit helps maintain code quality by running automated checks before commits are made.
-
Install git hooks:
pre-commit install --hook-type commit-msg --hook-type pre-commit --hook-type pre-push # it should output something like below: # pre-commit installed at .git/hooks/commit-msg # pre-commit installed at .git/hooks/pre-commit # pre-commit installed at .git/hooks/pre-push
These hooks perform different checks at various stages:
commit-msg
: Ensures commit messages follow the conventional formatpre-commit
: Runs Ruff linting and formatting checks before each commitpre-push
: Performs final validation before pushing to remote
-
Create a
.streamlit/secrets.toml
file:touch .streamlit/secrets.toml
-
Add MongoDB URI to
secrets.toml
:[mongo] uri = "mongodb+srv://<usr>:<pwd>@<xxxxxx.mongodb.net>/?retryWrites=true&w=majority&appName=Cluster0"
The MongoDB collections should mirror the structure of the CSV files in
src/data/YYYY_MM_DD_weather_station_data.csv
folder, with each document containing timestamp and sensor readings.
Running the web app locally is as simple as running the following command:
streamlit run src/app.py
Simply run the CLI tool directly with Python:
python src/cli.py --help
For convenience, you can set up an alias named meteorix
:
-
Add Project Root to PYTHONPATH:
# Get your project root path cd /path/to/weather-dashboard export PYTHONPATH="$(pwd):$PYTHONPATH"
-
Create CLI Alias:
# Create alias for the CLI tool alias meteorix="python src/cli.py"
-
Make Changes Permanent: Add these lines to your shell configuration file (
~/.bashrc
or~/.zshrc
):REPO_DIR="/path/to/weather-dashboard" PYTHON_PATH="$REPO_DIR/.venv/bin/python" CLI_PATH="$REPO_DIR/src/cli.py" alias meteorix="$PYTHON_PATH $CLI_PATH"
To get autocomplete working, you need to add the following to your shell configuration file (
~/.bashrc
or~/.zshrc
), this is the fastest way to manually adding cli commands vs usingregister-python-argcomplete
:# Add these lines to your `~/.bashrc`: # Meteorix CLI configuration export REPO_DIR="/path/to/weather-dashboard" export PYTHON_PATH="$REPO_DIR/.venv/bin/python" export CLI_PATH="$REPO_DIR/src/cli.py" # Create function wrapper for the CLI function meteorix { $PYTHON_PATH $CLI_PATH "$@" } # Pure bash completion - no Python involved function _meteorix_complete { local cur=${COMP_WORDS[COMP_CWORD]} local commands="upload delete check head tail info spit plot monitor eda ml who -h --help" if [ $COMP_CWORD -eq 1 ]; then COMPREPLY=($(compgen -W "$commands" -- "$cur")) fi } # Register completion complete -F _meteorix_complete meteorix
or
# Add these lines to your `~/.zshrc`: # Meteorix CLI configuration export REPO_DIR="/path/to/weather-dashboard" export PYTHON_PATH="$REPO_DIR/.venv/bin/python" export CLI_PATH="$REPO_DIR/src/cli.py" # Create function wrapper for the CLI function meteorix { $PYTHON_PATH $CLI_PATH "$@" } # Zsh completion function _meteorix { local commands="upload delete check head tail info spit plot monitor eda ml who -h --help" _arguments "1: :($commands)" } # Register completion compdef _meteorix meteorix
-
Apply Changes: Either:
- Restart your terminal, or
- Run:
source ~/.bashrc
(orsource ~/.zshrc
)
-
Show Available Commands:
meteorix --help
The following commands work with either method (replace meteorix
with python src/cli.py
if not using the alias):
# Show whoami
meteorix who
# Show available date range and file statistics
meteorix info
# Upload data for a specific date
meteorix upload 2024_03_20
# Show first/last 5 rows of data
meteorix head 2024_03_20
meteorix tail 2024_03_20
-
Create a Discord Bot Application:
- Log into the Discord Developer Portal
- Click "New Application" and give it a name
- Go to the "Bot" tab and click "Add Bot"
- Under the bot's username, click "Copy" to copy your bot's token
- In the Bot tab, enable the following Privileged Gateway Intents:
Message Content Intent
Server Members Intent
Presence Intent
- Make sure that Public Bot is enabled if you want others to invite your bot
- Disable Require OAuth2 Code Grant unless you specifically need it
Warning: Never share your bot token! If exposed, immediately regenerate it in the Developer Portal.
-
Invite the Bot to Your Server:
- Go to the "OAuth2 > URL Generator" tab
- Under "Scopes", select:
bot
applications.commands
messages.read
- Under "Bot Permissions", select:
Read Messages/View Channels
Send Messages
Send Messages in Threads
Embed Links
Attach Files
Read Message History
Add Reactions
Use Slash Commands
- Copy the generated URL and open it in a browser to invite the bot
-
Add Bot Token to
.streamlit/secrets.toml
:[bot_token] token = "YOUR_BOT_TOKEN" [channel_id] channel_1_id = "YOUR_CHANNEL_ID_1" channel_2_id = "YOUR_CHANNEL_ID_2" # add more channels as needed
You can start the bot immediately using
python src/meteorix.py
. However, to keep it running continuously, it's recommended to set up a systemd service: -
Create Systemd Service File:
sudo nano /etc/systemd/system/meteorix-bot.service
-
Add the following configuration (adjust paths and username):
[Unit] Description=Meteorix Discord Bot After=network.target [Service] Type=simple User=YOUR_USERNAME WorkingDirectory=/path/to/weather-dashboard Environment="PATH=/path/to/weather-dashboard/.venv/bin" ExecStart=/path/to/weather-dashboard/.venv/bin/python /path/to/weather-dashboard/src/meteorix.py Restart=always RestartSec=10 [Install] WantedBy=multi-user.target
-
Enable and Start the Service:
# Enable the service to start on boot sudo systemctl enable meteorix-bot # Start the service sudo systemctl start meteorix-bot # Check service status sudo systemctl status meteorix-bot
-
Common Service Commands:
# Stop the bot sudo systemctl stop meteorix-bot # Restart the bot (after code changes) sudo systemctl restart meteorix-bot # View live logs sudo journalctl -u meteorix-bot -f
-
Mention Commands:
@meteorix help # Show all commands @meteorix info # Show available date range @meteorix head # Show earliest timestamp @meteorix tail # Show latest timestamp
-
Slash Commands:
/help # Show all commands /info # Show available date range /head 2024_03_20 # Show first 5 rows of specific date /tail # Show latest timestamp
📦weather-dashboard
┣ 📂.devcontainer // Dev container configuration
┣ 📂.github // GitHub workflows and actions
┣ 📂.streamlit // Streamlit configuration files
┃ ┣ 📄config.toml // App configuration
┃ ┗ 📄secrets.toml // Secrets configuration
┣ 📂lib // Library and documentation files
┃ ┣ 📂fig // Plots and images
┃ ┣ 📄project_instructions.pdf
┃ ┣ 📄project_presentation.pdf
┃ ┣ 📄project_proposal.md
┃ ┗ 📄project_report.md
┣ 📂src // Source code files
┃ ┣ 📂cli_components // CLI components
┃ ┣ 📂web_components // Dashboard components
┃ ┣ 📂data // Data and analysis scripts
┃ ┣ 📄app.py // Web app main script
┃ ┣ 📄cli.py // CLI tool main script
┃ ┗ 📄meteorix.py // Discord bot script
┣ 📄.gitignore
┣ 📄.pre-commit-config.yaml
┣ 📄.pre-commit_msg_template.py
┣ 📄LICENSE
┣ 📄README.md
┗ 📄requirements.txt // Python dependencies