CRC Bot is a currency converter with built-in calculator and monitoring of exchange rates, which are updated every day via exchange-api. The converter is always active, just send a number or math expression. The result of the expression will be automatically calculated and converted to the final currency.
See running bot: @CRC2_bot
The bot is originally designed to be used when traveling for quick price orientation in stores and quick small calculations. But later I realized that the bot is suitable not only for this purpose and added commands for working with currency pairs, which speeds up the work from the desktop.
Perhaps later I will add a subscription to notifications about currency pair rate changes with the ability to set threshold values.
- Setting the currency pair and rounding mode
- Solving a user-sent mathematical expressions before converting
- Converting a value sent via message or the result of a user-sent math expression
- Sending the exchange rate of the currency pair
- Saving user settings in database (currency pair and rounding mode)
- python-dotenv 1.0.1
- python 3.11.4
- aiogram 3.1.1
- aiosqlite 0.19.0
- aiohttp 3.8.5
- cexprtk 0.4.1
The full list of used libraries is in requirements.txt
pip install -r requirements.txt
To run the bot, you need to specify Telegram Bot API Token — Get token
The get_token.py script allows you to get Telegram Bot API token from .txt file when the bot is running locally or from environment variables when you want to deploy the bot.
- Create an env folder with the "tg_token.txt" file in the directory from which you will run the main.py and add to file your Telegram Bot API token
- Install all libraries from requirements.txt
- Run the main script — main.py from src/crc-bot directory
P.S. Bot token and database are hidden in .gitignore
# ignore secret config
bot_token.txt
db.sqlite
The project is deployed via Railway. You can use any other cloud service or hosting, but if you want to use Railway, you need to:
- Set up automatic deployments by specifying the required branch of your project in Railway
- Specify path to the entry point (main.py) in Railway
- List all libraries in requirements.txt
- Specify Python version in runtime.txt
- Specify your Telegram Bot API in Railway variables
- main.py — the main script that runs a bot polling, a scheduler for updating exchange rates and includes message handlers from all other modules through the router
- menu.py — menu markup generation
- db.py — creating a database and working with it
- get_token.py — getting Telegram Bot API token from environment variables (for deploy) or .txt files (for local run)
- bot.py — bot instance module
- rates.py — getting all exchange rates via async request to exchangerate-api
- checks.py — methods and variables that are often used in other modules for checking different things
- currencies.py — all currencies supported by exchangerate-api with emoji flags
- round.py — Round menu button handler
- set_currencies.py — From/To menu buttons handler and generation of inline currency buttons
- rate.py — Rate menu button handler
- converter — converter handler, conversion with built-in calculation function
- start.py — start command handler
- help.py — help command handler
- about.py — about command handler and inline link-buttons
- curr_commands.py — currency commands (/from /to /pair /swap)