///
This guide will walk you through the process of setting up and installing the Air Quality Bot from the `air-quality` repository, focusing on the `bot_refactor_test.py` script.
57 views
~57 views from guests
Guest views are estimated from total page views. These include anonymous visitors and users who weren't logged in when they viewed the page.
This guide will walk you through the process of setting up and installing the Air Quality Bot from the air-quality repository, focusing on the bot_refactor_test.py script.
Before you begin, ensure you have the following installed and configured:
First, clone the air-quality repository to your local machine using Git:
Navigate into the cloned directory and install the required Python libraries using pip:
pyTelegramBotAPI (installed as telebot) is used for interacting with the Telegram Bot API.requests is used for making HTTP requests to external APIs (like AirVisual).The bot requires a keys.json file in the root directory to store your API keys and bot-specific settings.
Create keys.json: In the air-quality directory, create a file named keys.json with the following structure:
Fill in your keys:
"YOUR_AIRVISUAL_API_KEY" with the API key you obtained from IQAir."YOUR_TELEGRAM_BOT_TOKEN" with the bot token provided by BotFather."aqius_prior": 0 is an initial value for tracking changes in air quality. You can keep it as 0. The bot will update this value automatically.Set your Chat ID: The CHAT_ID where the bot sends messages is hardcoded in bot_refactor_test.py for testing purposes. You need to change this to your desired Telegram chat ID.
Open bot_refactor_test.py and locate the line:
Change 712191968 to your specific Telegram chat ID. You can find your chat ID by forwarding a message from your target chat to a bot like @userinfobot.
Once all dependencies are installed and the keys.json file is configured, you can run the bot:
The bot will start, and you should see a "Test message sent!" confirmation in your console, indicating that the bot has successfully initialized and sent a message to the specified CHAT_ID. It will then proceed to fetch and send air quality updates according to its schedule, as detailed in the [Air Quality Bot Overview].