Skip to content

Commit

Permalink
Create config.py
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH authored Aug 7, 2024
1 parent 3594c58 commit d678b87
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions projects/piguardian/utils/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import os
import json

class Config:
def __init__(self):
self.config_file = 'config.json'
self.load_config()

def load_config(self):
if os.path.exists(self.config_file):
with open(self.config_file, 'r') as f:
self.config = json.load(f)
else:
self.config = {
'api_url': 'https://example.com/api',
'api_key': 'YOUR_API_KEY',
'database_url': 'sqlite:///database.db',
'logging_level': 'INFO'
}
self.save_config()

def save_config(self):
with open(self.config_file, 'w') as f:
json.dump(self.config, f, indent=4)

def get(self, key):
return self.config.get(key)

config = Config()

0 comments on commit d678b87

Please sign in to comment.