1
Fork 0
mirror of https://github.com/Steffo99/greed.git synced 2024-11-22 05:54:18 +00:00

Add config code

This commit is contained in:
Steffo 2017-12-06 15:40:12 +01:00
parent 398ff443e3
commit 6091295563
WARNING! Although there is a key with this ID in the database it does not verify this commit! This commit is SUSPICIOUS.
GPG key ID: C27544372FBB445D
3 changed files with 38 additions and 0 deletions

2
.gitignore vendored
View file

@ -100,3 +100,5 @@ ENV/
# mypy # mypy
.mypy_cache/ .mypy_cache/
.idea/ .idea/
config/config.ini

View file

@ -0,0 +1,13 @@
# greed configuration file
# Config file parameters
[Config]
; Config file version. DO NOT EDIT THIS!
version = 1
; Set this to no when you are done editing the file
is_template = yes
# Telegram bot parameters
[Telegram]
; Your bot token goes here. Get one from @BotFather!
token = 123456789:YOUR_TOKEN_GOES_HERE_______________

23
core.py Normal file
View file

@ -0,0 +1,23 @@
import os
import sys
import configparser
# Check if a configuration file exists and create one if it doesn't
if not os.path.isfile("config/config.ini"):
# Copy the template file to the config file
with open("config/template_config.ini") as template_file, open("config/config.ini", "w") as config_file:
config_file.write(template_file.read())
# Create a configparser
config = configparser.ConfigParser()
# Read the config file into the configparser
with open("config/config.ini") as config_file:
config.read_file(config_file)
# Check if the file has been edited correctly
if config["Config"]["is_template"] == "yes":
print("A config file has been created in config/config.ini.")
print("Edit it with your configuration, set the is_template flag to false and restart this script.")
sys.exit(1)
print("Program goes here")