-
Notifications
You must be signed in to change notification settings - Fork 13
/
config.py
44 lines (36 loc) · 937 Bytes
/
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import time
import yaml
import log
class YamlAttrs:
def __init__(self, filename, defaults=None):
self.filename = filename
try:
with open(filename, 'r', encoding='utf-8') 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', encoding='utf-8') 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={
'advent_of_code_last_check': int(time.time()),
'gateway_url': None,
'instagram': {},
'reddit_access_token': None,
'steam_news_ids': {},
'timers': {},
'tweet_ids': {},
'twitch_last_times': {},
'twitter_last_post_time': None,
'twitter_queue': [],
})