forked from raylu/sbot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.py
More file actions
34 lines (27 loc) · 755 Bytes
/
config.py
File metadata and controls
34 lines (27 loc) · 755 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
28
29
30
31
32
33
34
import yaml
import log
class YamlAttrs:
def __init__(self, filename, defaults=None):
self.filename = filename
try:
with open(filename, 'r') as f:
doc = yaml.safe_load(f)
except FileNotFoundError:
doc = defaults
log.write('creating ' + self.filename)
self.save()
for k, v in doc.items():
setattr(self, k, v)
def save(self):
with open(self.filename, 'w') as f:
data = dict(self.__dict__)
del data['filename']
yaml.dump(data, f)
def __str__(self):
return '%s %s' % (self.__class__, self.__dict__)
bot = YamlAttrs('config.yaml')
state = YamlAttrs('state.yaml',
defaults={
'gateway_url': None, 'timers': {}, 'reddit_access_token': None,
'tweet_ids': {}, 'steam_news_ids': {}, 'twitch_last_times': {},
})