From aa7bb5087c6dc568ea16f53788f9f77d653ad239 Mon Sep 17 00:00:00 2001 From: Ian Andwati Date: Sun, 15 May 2022 15:41:13 +0300 Subject: [PATCH] refactored to use python-dotenv --- Pipfile | 1 + Pipfile.lock | 10 +++++++++- src/bot.py | 9 ++++++--- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/Pipfile b/Pipfile index d704dbc..73c9d61 100644 --- a/Pipfile +++ b/Pipfile @@ -6,6 +6,7 @@ name = "pypi" [packages] flask = "*" pytelegrambotapi = "*" +python-dotenv = "*" [dev-packages] black = "*" diff --git a/Pipfile.lock b/Pipfile.lock index 44d8b2c..f38578f 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "cfe1776842e1b6d668d14da0cafb880fee01d3e063bb59e87600b71e8aa8762f" + "sha256": "cbb3e6170d64d57e8b7b6902b88c292dff7241868ddc303f01b2e1d7a50e817d" }, "pipfile-spec": 6, "requires": { @@ -132,6 +132,14 @@ "index": "pypi", "version": "==4.5.1" }, + "python-dotenv": { + "hashes": [ + "sha256:b7e3b04a59693c42c36f9ab1cc2acc46fa5df8c78e178fc33a8d4cd05c8d498f", + "sha256:d92a187be61fe482e4fd675b6d52200e7be63a12b724abbf931a40ce4fa92938" + ], + "index": "pypi", + "version": "==0.20.0" + }, "requests": { "hashes": [ "sha256:68d7c56fd5a8999887728ef304a6d12edc7be74f1cfa47714fc8b414525c9a61", diff --git a/src/bot.py b/src/bot.py index 6d52e6a..22e5be7 100644 --- a/src/bot.py +++ b/src/bot.py @@ -1,14 +1,17 @@ -from os import environ +import os import requests import telebot +from dotenv import load_dotenv -bot = telebot.TeleBot(environ["TELEGRAM_TOKEN"]) +load_dotenv() + +bot = telebot.TeleBot(os.getenv("TELEGRAM_TOKEN")) # configure the webhook for the bot bot.set_webhook( "https://{}.herokuapp.com/{}".format( - environ["PROJECT_NAME"], environ["TELEGRAM_TOKEN"] + os.getenv("PROJECT_NAME"), os.getenv("TELEGRAM_TOKEN") ) )