Skip to content

Commit

Permalink
Add timezone conf (#247)
Browse files Browse the repository at this point in the history
* Adding TZ support
  • Loading branch information
mazzi authored Feb 2, 2023
1 parent eb3bfe3 commit 7958972
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export PYTHONPATH=./src/
export KEITHFEM_BASE_URL=
export HTTP_API_TOKEN=
export DADJOKE_URL=https://icanhazdadjoke.com/
export TIMEZONE='Europe/Berlin'
```

KEITHFEM_BASE_URL is the [airtime](https://www.airtime.pro/) base url of the radio.
Expand All @@ -32,5 +33,7 @@ HTTP_API_TOKEN is from [@Botfather](https://web.telegram.org/#/im?p=@BotFather)

DADJOKE_URL is a jokes service.

TIMEZONE is the TZ where the bot is running. Usually paired with airtime service TZ. If not set 'Europe/London' will be used.


<sub><sup>Keith F'em, a community radio experiment, is presented by Keith in conjunction with SP2. [email protected]</sup></sub>
1 change: 1 addition & 0 deletions src/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
HTTP_API_TOKEN = os.environ.get("HTTP_API_TOKEN", "")
KEITHFEM_BASE_URL = os.environ.get("KEITHFEM_BASE_URL", "")
DADJOKE_URL = os.environ.get("DADJOKE_URL", "")
TIMEZONE = os.environ.get("TIMEZONE", "Europe/London")
8 changes: 7 additions & 1 deletion src/keithfembot.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import logging
import os
import time

from telegram.ext import CallbackContext, CommandHandler, Updater

from clients.http import HTTPClient
from commands import About, Donate, Help, Joke, Next, Now, Today, Tomorrow, Week
from config import HTTP_API_TOKEN
from config import HTTP_API_TOKEN, TIMEZONE

logging.basicConfig(
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", level=logging.INFO
Expand All @@ -22,6 +24,10 @@ def error_handler(update: object, context: CallbackContext) -> None:

def main(http_client=None) -> None:
"""Starts the bot."""

os.environ["TZ"] = TIMEZONE
time.tzset() # Unix only function

updater = Updater(token=HTTP_API_TOKEN, use_context=True)

dp = updater.dispatcher # type: ignore
Expand Down

0 comments on commit 7958972

Please sign in to comment.