-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.py
29 lines (26 loc) · 1.05 KB
/
config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import configparser
import os
import sys
class Config:
def __init__(self):
config = configparser.ConfigParser()
# check whether config file exists, else write example file
if os.path.isfile('config.ini'):
config.read('config.ini')
if 'DATABASE' in config:
self.address = config['DATABASE']['address']
self.username = config['DATABASE']['username']
self.password = config['DATABASE']['password']
self.database_name = config['DATABASE']['database_name']
else:
sys.exit(0)
else:
print("No config file found, please fill config.ini with your properties")
config['DATABASE'] = {
'address': 'address-to-database',
'username': 'your-username',
'password': 'your-password',
'database_name': 'name-of-database-for-data'}
with open('config.ini', 'w') as configfile:
config.write(configfile)
sys.exit(0)