Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

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

NotificationsYou must be signed in to change notification settings

alifeee/pollen_bot

Repository files navigation

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

It uses theMet Office's pollen forecast

Messagehttps://t.me/pollen_count_bot on Telegram to use.

Requirements

RequirementVersion
Python3.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, seehelp page, but in essence, talk to theBotFather.

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 thePersistence API frompython-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 updatesudo apt install python3.11-venvsudo mkdir -p /usr/alifeeesudo chown alifeee:alifeee /usr/alifeeecd /usr/alifeeegit clone git@github.com:alifeee/pollen_bot.gitsudo adduser --system --no-create-home --group pollen_bot# sudo cat /etc/group# sudo cat /etc/passwd# sudo -u pollen_bot whoamipython3 -m venv env./env/bin/pip install -r requirements.txtsudo 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.servicesudo systemctlenable pollen_bot.servicesudo systemctl start pollen_bot.servicesudo systemctl status pollen_bot.service

With runit

runit is a bit like systemd. SeeFAQ.

mkdir /home/alifeee/python/pollen_bot/logssudo mkdir /etc/sv/pollen_botsudoecho'#!/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/runsudo mkdir /etc/sv/pollen_bot/logsudoecho'#!/bin/sh  exec svlogd -tt /home/alifeee/python/pollen_bot/logs'> /etc/sv/pollen_bot/log/runsudo ln -s /etc/sv/pollen_bot /etc/service/sudo sv start pollen_botsudo sv stop pollen_botsudo sv status pollen_botsudo 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_botgit pullsudo sv restart pollen_bot

About

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

Topics

Resources

Stars

Watchers

Forks


[8]ページ先頭

©2009-2025 Movatter.jp