mirror of
https://github.com/Steffo99/greed.git
synced 2024-11-22 14:04:18 +00:00
Add config code
This commit is contained in:
parent
398ff443e3
commit
6091295563
3 changed files with 38 additions and 0 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -100,3 +100,5 @@ ENV/
|
||||||
# mypy
|
# mypy
|
||||||
.mypy_cache/
|
.mypy_cache/
|
||||||
.idea/
|
.idea/
|
||||||
|
|
||||||
|
config/config.ini
|
13
config/template_config.ini
Normal file
13
config/template_config.ini
Normal 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
23
core.py
Normal 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")
|
Loading…
Reference in a new issue