Skip to content

Commit

Permalink
use Europe/Kiev timezone instead of UTC
Browse files Browse the repository at this point in the history
  • Loading branch information
yurnov committed Mar 25, 2024
1 parent 886e5a3 commit e6b25bf
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .env.exmple
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ TOKEN=<TOKEN>
CHAT_ID=<CHAT_ID>
# URL of API with compatiable format with http://alerts.net.ua/explosives_statuses_v2.json, optional
# URL=http://alerts.net.ua/explosives_statuses_v2.json
# Timezone, optional, default Europe/Kiev
# TIMEZONE=Europe/Kiev
# List of regions to filter, don't use spaces, single line, optional
# REGION_LIST="Одеська область","Київська область","Житомирська область","м. Київ","Львівська область"
# Full list of regions:
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ LABEL org.opencontainers.image.authors="Yuriy Novostavskiy" \
org.opencontainers.image.license="MIT" \
org.opencontainers.image.description="A simple bot that sends the update of alarms and exlosions"

RUN python -m pip install requests~=2.31.0 python-dotenv~=1.0.1
RUN python -m pip install requests~=2.31.0 python-dotenv~=1.0.1 pytz==2024.1

WORKDIR /bot

Expand Down
16 changes: 14 additions & 2 deletions bot/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
import os
from dotenv import load_dotenv
import time
from datetime import datetime
from datetime import datetime, timedelta
from pytz import timezone

"""
This is a simple telegram bot that every 30 secound get API http://alerts.net.ua/explosives_statuses_v2.json and send
Expand Down Expand Up @@ -45,6 +46,7 @@
CHAT_ID = os.getenv("CHAT_ID")
URL = os.getenv("URL")
REGION_LIST = os.getenv("REGION_LIST").split(",") if os.getenv("REGION_LIST") else None
TIMEZONE = os.getenv("TIMEZONE")

"""
Full list of regions:
Expand Down Expand Up @@ -112,9 +114,16 @@
else:
REGION_LIST = [region.strip('"') for region in REGION_LIST]

if not TIMEZONE:
logger.warning(
"TIMEZONE is not defined in .env file, using a default timezone Europe/Kiev"
)
TIMEZONE = "Europe/Kiev"

logger.info(f"Bot started with CHAT_ID: {CHAT_ID}")
logger.info(f"Following regions will be monitored: {REGION_LIST}")


def get_data():
try:
response = requests.get(URL)
Expand Down Expand Up @@ -162,7 +171,10 @@ def main():
region
):
logger.info(f"Explosion in region: {region}, date: {date}")
message += f"{regions_gram_case.get(region, region)} о {datetime.strptime(date,'%Y-%m-%dT%H:%M:%S+00:00').strftime('%H:%M')}\n"

message += f"{regions_gram_case.get(region, region)} о {datetime\
.strptime(date,'%Y-%m-%dT%H:%M:%S+00:00')\
.replace(tzinfo=timezone.utc).astimezone(TIMEZONE).strftime('%H:%M')}\n"

if message != MESSAGE:
message += "\nЙобанарусня!"
Expand Down

0 comments on commit e6b25bf

Please sign in to comment.