Добавил чтение конфига

This commit is contained in:
Lulzette 2021-09-17 15:50:18 +03:00
parent 28b98a9127
commit 539d53d209
2 changed files with 21 additions and 5 deletions

4
config.ini Normal file
View File

@ -0,0 +1,4 @@
[DB]
host=localhost
port=27017
name=pycms

22
main.py
View File

@ -15,18 +15,30 @@ class Config:
""" """
Init init Init init
""" """
mongoclient = pymongo.MongoClient('localhost', 27017) self.readConfig()
database = mongoclient['pycms']
mongoclient = pymongo.MongoClient(self.host, self.port)
database = mongoclient[self.dbname]
# TODO: Create table if not exists
posts = database['posts'] posts = database['posts']
self.posts = posts self.posts = posts
def readConfig(): def readConfig(self):
""" """
Read config file, if not exists - call Init.createConfig() Read config file, if not exists - call Init.createConfig()
""" """
pass import configparser
config = configparser.ConfigParser()
config.read('config.ini')
def createConfig(): db = config['DB']
self.host = db['host']
self.port = int(db['port'])
self.dbname = db['name']
def createConfig(self):
""" """
Create config file Create config file
""" """