Important
This repository is an educational demo MVP created for a YouTube tutorial. It is intentionally small and is not intended to be production-ready.
The original video is in Ukrainian. English auto-dubbing is also available.
- Read the tutorial: English | Українська
- Try the tutorial demo: @codex_time_bot
- Explore the full-featured production bot: @cryptocodi_bot | Source code
This repository contains the educational time-conversion MVP used in the
tutorial. @codex_time_bot is its deployed demo, while @cryptocodi_bot is a
larger production project with its complete source code available publicly.
Codex Time Bot is a Telegram bot that finds time and timezone expressions in messages and converts them between Kyiv, Central European, and UTC time.
- Parses expressions with or without a space:
10:00 utcand10:00utc. - Finds time expressions inside longer text messages.
- Supports multiple unique expressions in one message.
- Converts every match in the fixed order: KYIV, CET, UTC.
- Uses timezone rules instead of fixed offsets:
UTCEurope/KyivEurope/Viennafor the MVPCETlabel
- Applies daylight-saving rules provided by Python
zoneinfo. - Ignores unsupported expressions and messages without matches.
- Replies directly to the original Telegram message.
Example response:
10:00 UTC ┬─> 13:00 KYIV
├─> 12:00 CET
└─> 10:00 UTC
UTC — UTC (UTC+00:00)
Explicit offsets such as 10:00 UTC+2 are not supported in the MVP and are
ignored.
- Python 3.12
- A Telegram bot token
Clone the repository and enter the project directory:
git clone https://github.com/deKibi/codex-time-bot.git
cd codex-time-botCreate and activate a virtual environment:
python3 -m venv .venv
source .venv/bin/activateInstall production dependencies:
python -m pip install --upgrade pip
python -m pip install -r requirements.txtCreate the local configuration file:
cp .env.example .envEdit .env and replace the placeholder token:
TELEGRAM_BOT_TOKEN=replace_with_your_telegram_bot_token
MAX_TIME_MATCHES_PER_MESSAGE=5MAX_TIME_MATCHES_PER_MESSAGE limits unique time and timezone pairs. Duplicate
pairs do not count toward the limit.
python main.pyThe bot uses Telegram long polling. Send it a text message containing a supported time expression; messages without matches are ignored.
Install development dependencies:
python -m pip install -r requirements-dev.txtRun all tests:
python -m pytestTests also run in GitHub Actions on Ubuntu 24.04 with Python 3.12.
Logs are written to both the console and logs/bot.log. File logs rotate daily,
and the latest 30 rotated files are retained. Original Telegram message text and
bot tokens are not logged.
This option runs the bot manually inside a GNU screen session under a regular
Linux user. It is simple and lets you reconnect to the bot session, but it does
not start the bot automatically after a server reboot.
Install the required system packages:
sudo apt update
sudo apt install -y git python3 python3-venv screenClone and configure the project in the regular user's home directory:
cd ~
git clone https://github.com/deKibi/codex-time-bot.git
cd codex-time-bot
python3 -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade pip
python -m pip install -r requirements.txt
cp .env.example .env
nano .envCheck the project path. This is only an example path to the cloned GitHub repository; replace it with the actual path on your server where needed:
pwd
# Example output:
# /home/denys/codex-time-botStart a named screen session:
screen -S codex-time-botInside the screen session, start the bot:
source .venv/bin/activate
python main.pyUseful screen controls:
- Detach while keeping the bot running: press
Ctrl+A, thenD. - Reconnect to the bot session:
screen -r codex-time-bot. - List sessions:
screen -ls. - Stop the bot after reconnecting: press
Ctrl+C.
Use this option when the bot should start together with the system and restart after crashes.
First complete the clone and configuration setup from the simple screen run
section above. Then create a systemd service file:
sudo nano /etc/systemd/system/codex-time-bot.serviceExample service configuration:
[Unit]
Description=Codex Time Bot
After=network-online.target
Wants=network-online.target
[Service]
Type=simple
User=denys
WorkingDirectory=/home/denys/codex-time-bot
Environment=PYTHONUNBUFFERED=1
ExecStart=/home/denys/codex-time-bot/.venv/bin/python main.py
Restart=on-failure
RestartSec=5
[Install]
WantedBy=multi-user.targetIn this example, denys is the regular Linux user that runs the bot, and
/home/denys/codex-time-bot is only an example project path. Replace User,
WorkingDirectory, and the path in ExecStart with your actual values.
Enable and start the service:
sudo systemctl daemon-reload
sudo systemctl enable codex-time-bot
sudo systemctl start codex-time-botCheck service status:
sudo systemctl status codex-time-botIf the bot runs as a systemd service, make sure it is not also running in a
parallel screen session to avoid running two bot instances at the same time.
List existing screen sessions with:
screen -lsUseful service commands:
sudo systemctl stop codex-time-bot
sudo systemctl restart codex-time-botUseful autostart commands:
sudo systemctl enable codex-time-bot
sudo systemctl disable codex-time-bot- Enable autostart after reboot:
sudo systemctl enable codex-time-bot. - Disable autostart after reboot:
sudo systemctl disable codex-time-bot. - Disabling autostart does not stop the currently running service; use
sudo systemctl stop codex-time-botfor that.
Logs:
sudo journalctl -u codex-time-bot -f