-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.py
More file actions
27 lines (22 loc) · 700 Bytes
/
Copy pathconfig.py
File metadata and controls
27 lines (22 loc) · 700 Bytes
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
import json
import os
DEFAULT_CONFIG = {
'api_key': 'your_api_key',
'api_secret': 'your_api_secret',
'base_currency': 'USD',
'timeout': 30
}
class ConfigLoader:
def __init__(self, config_file='config.json'):
self.config_file = config_file
self.config = self.load_config()
def load_config(self):
if os.path.exists(self.config_file):
with open(self.config_file, 'r') as file:
return {**DEFAULT_CONFIG, **json.load(file)}
return DEFAULT_CONFIG
def get(self, key, default=None):
return self.config.get(key, default)
if __name__ == '__main__':
loader = ConfigLoader()
print(loader.get('api_key'))