GithubHelp home page GithubHelp logo

alifeee / pollen_bot Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 198 KB

A telegram bot to notify you when the pollen count is high, using the UK's Met Office Pollen Forecast (UK only)

Home Page: https://t.me/pollen_count_bot

Python 100.00%
forecast met-office pollen telegram-bot

pollen_bot's Introduction

Pollen bot

This is a Telegram bot, to send you a message every time the pollen threshold reaches above a certain level.

It uses the Met Office's pollen forecast

Message https://t.me/pollen_count_bot on Telegram to use.

Requirements

Requirement Version
Python 3.11.1

Commands

Set up environment

pip install -r requirements.txt

Run

python bot.py

Run and run scheduled tasks on startup

python bot.py start

Telegram credentials

To obtain an access token for telegram, see help page, but in essence, talk to the BotFather.

The access token is used via an environment variable, or a .env file, which is not tracked by git.

Also in the environment should be an "admin ID", where errors are sent via the error handler.

touch .env
TELEGRAM_BOT_ACCESS_TOKEN=...
ADMIN_USER_ID=...

Persistent data

To store each user's location, reminder preference, and reminder threshold, a persistent pickle file is used. This is not tracked by git. This uses the Persistence API from python-telegram-bot.

persistent_data = PicklePersistence(filepath="bot_data.pickle")
application = Application.builder().token(API_KEY).persistence(persistent_data).build()

Deploy on remote server

Set up environment on server (Linux)

ssh alifeee@...
sudo apt-get update
sudo apt install python3.11-venv
sudo mkdir -p /usr/alifeee
sudo chown alifeee:alifeee /usr/alifeee
cd /usr/alifeee
git clone [email protected]:alifeee/pollen_bot.git
sudo adduser --system --no-create-home --group pollen_bot
# sudo cat /etc/group
# sudo cat /etc/passwd
# sudo -u pollen_bot whoami
python3 -m venv env
./env/bin/pip install -r requirements.txt
sudo chown -R alifeee:pollen_bot .

Move over secrets

scp .env alifeee@...:~/python/pollen_bot/
sudo chown -R alifeee:pollen_bot .env

Set up to run as a process

With systemd

cp pollen_bot.service /etc/systemd/system/pollen_bot.service
sudo systemctl enable pollen_bot.service
sudo systemctl start pollen_bot.service
sudo systemctl status pollen_bot.service

With runit

runit is a bit like systemd. See FAQ.

mkdir /home/alifeee/python/pollen_bot/logs
sudo mkdir /etc/sv/pollen_bot
sudo echo '#!/bin/sh
  #cd /home/alifeee/python/pollen_bot & ./env/bin/python3 bot.py
  # redirect stderr to stdout
  exec 2>&1
  # start program
  exec /home/alifeee/python/pollen_bot/env/bin/python3 /home/alifeee/python/pollen_bot/bot.py
  ' > /etc/sv/pollen_bot/run
sudo mkdir /etc/sv/pollen_bot/log
sudo echo '#!/bin/sh
  exec svlogd -tt /home/alifeee/python/pollen_bot/logs
  ' > /etc/sv/pollen_bot/log/run
sudo ln -s /etc/sv/pollen_bot /etc/service/

sudo sv start pollen_bot
sudo sv stop pollen_bot
sudo sv status pollen_bot
sudo sv restart pollen_bot

Logs

Log files are stored in the folder specified above, so for this script, they are in ~/python/pollen_bot/logs.

Update

ssh alifeee@...
cd ~/python/pollen_bot
git pull
sudo sv restart pollen_bot

pollen_bot's People

Contributors

alifeee avatar

Stargazers

Benjamin Parry avatar

Watchers

 avatar

pollen_bot's Issues

Make /start friendlier

Use keyboard buttons etc. to show choices to user

Currently, you must know the exact region list, and the desired "Yes/No" (with capitalisation), to actually use the bot.

allow "no forecast"

The Met Office only does the pollen forecast in summer. The bot should deal with that.

image

Currently it just errors because it expects the forecast to be in the HTML page

image

Text formatting

Use telegram bot's extensive text formatting and/or send images, to make the messages look nice.

Currently, they're just plaintext.

Let's have a bit of pizzazz

Refactor code

Make the forecast into an object, rather than throwing around dictionaries.

Collect common functions into the forecast.py file.

Clean up code generally.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.