Skip to content

rin-gil/open-weather-bot

Repository files navigation

Open Weather Bot

python version aiogram version aiohttp version aiosqlite version APScheduler version environs version Pillow version tzlocal version Code style: black Code tests Code tests MIT licence

Ru Ua

Open Weather Bot

Telegram bot that shows the weather forecast. The working version is available at @OpenWeatherSmartBot

Features

  • City search by name or coordinates
  • 24-hour weather and forecast display
  • Updating weather forecast every 3 hours

Installation

git clone https://github.com/rin-gil/OpenWeatherBot.git
cd OpenWeatherBot
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
mv .env.dist .env

OpenWeatherBot home screen

Setup and run

  • Register a new bot with @BotFather and copy the received token
  • Paste the bot's token into the .env file
  • Register an account at OpenWeatherMap
  • Create API key and copy it to .env file
  • Paste your Telegram id into the .env file
  • Find out your id, for example, by writing bot @getmyid_bot
  • Launch the bot via the bot.py file python bot.py

Localization

  • Since version 1.1.0 the bot added localization for English, Ukrainian and Russian
  • To add a translation in your language, do the following:
    1. go to the folder with the bot

    2. activate the virtual environment:

      source venv/bin/activate

    3. create a translation file for your language, where {language} is the ISO 639-1 language code

      pybabel init --input-file=tgbot/locales/tgbot.pot --output-dir=tgbot/locales --domain=tgbot --locale={language}

    4. translate the lines in the file locales/{language}/LC_MESSAGES/tgbot.po

    5. compile the translation with the command:

      pybabel compile --directory=tgbot/locales --domain=tgbot

    6. restart the bot

  • If you change the lines to be translated in the code, you will need to completely recreate and compile the translation files for all localizations:
    1. extract strings to be translated from the code:

      pybabel extract --input-dirs=./tgbot --output-file=tgbot/locales/tgbot.pot --sort-by-file --project=OpenWeatherBot

    2. create translation files for all localizations:

      pybabel init --input-file=tgbot/locales/tgbot.pot --output-dir=tgbot/locales --domain=tgbot --locale={language}

    3. compile translations:

      pybabel compile --directory=tgbot/locales --domain=tgbot

  • You can read more about this in the example from the documentation of aiogram

Developers

Licenses