Read setup variables from environment variables

Also Adds support for heroku env variables

Signed-off-by: lzzy12 <jhashivam2020@gmail.com>
This commit is contained in:
lzzy12 2019-12-09 15:02:16 +05:30
parent 97ed788aa5
commit 6c66a2ad8a
5 changed files with 12 additions and 18 deletions

5
.gitignore vendored
View File

@ -1,7 +1,4 @@
*.env
config.ini
*conf.ini
conf.ini
config.env
*auth_token.txt
*.pyc
downloads/*

View File

@ -38,7 +38,7 @@ sudo pacman -S docker python
## Setting up config file
```
cp bot/config_sample.ini bot/config.ini
cp config_sample.env config.env
```
- Remove the first line saying:
```
@ -87,7 +87,6 @@ sudo docker run mirror-bot
```
python3 generate_drive_token.py
```
- Change Bot Download Dir to /bot/downloads in config.ini file.
- Install [Heroku cli](https://devcenter.heroku.com/articles/heroku-cli)
- Login into your heroku account with command:
```
@ -107,7 +106,7 @@ heroku stack:set container
```
- Add Private Credentials and Config Stuff:
```
git add -f credentials.json token.pickle ./bot/config.ini
git add -f credentials.json token.pickle config.env
```
- Commit new changes:
```

View File

@ -1,10 +1,9 @@
import logging
import configparser
import aria2p
import threading
from telegram.ext import Updater
from telegram import Bot
import os
from dotenv import load_dotenv
import time
botStartTime = time.time()
@ -16,12 +15,11 @@ logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s
handlers=[logging.FileHandler('log.txt'), logging.StreamHandler()],
level=logging.INFO)
config = configparser.ConfigParser()
config.read('bot/config.ini')
load_dotenv('config.env')
def getConfig(name: str):
return config['DEFAULT'][name]
return os.environ[name]
LOGGER = logging.getLogger(__name__)

View File

@ -1,11 +1,10 @@
#Remove this line before deploying
_____REMOVE_THIS_LINE_____=True
[DEFAULT]
# ENTER BOT TOKEN (Get your BOT_TOKEN by talking to @botfather)
BOT_TOKEN =
GDRIVE_FOLDER_ID =
DOWNLOAD_DIR = /home/username/mirror-bot/downloads
DOWNLOAD_STATUS_UPDATE_INTERVAL = 5
AUTO_DELETE_MESSAGE_DURATION = 20
BOT_TOKEN = ""
GDRIVE_FOLDER_ID = ""
OWNER_ID =
DOWNLOAD_DIR = "/home/username/mirror-bot/downloads"
DOWNLOAD_STATUS_UPDATE_INTERVAL = 5
AUTO_DELETE_MESSAGE_DURATION = 20

View File

@ -10,3 +10,4 @@ uritemplate>=3.0.0
urllib3>=1.23
aria2p
mimelib
python-dotenv>=0.10