-
Notifications
You must be signed in to change notification settings - Fork 2
/
config.py
79 lines (62 loc) · 2 KB
/
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import yaml
class WxPusherConfig:
def __init__(self, appToken: str, topicIds: list):
self.appToken = appToken
self.topicIds = topicIds
class WeChatWorkConfig:
def __init__(self, webhookKey: str):
self.webhookKey = webhookKey
class WeatherConfig:
def __init__(self, apiKey: str, city: int):
self.apiKey = apiKey
self.city = city
class LoverConfig:
def __init__(
self,
expressLoveTimestamp: int,
meetingTimestamp: int,
monthOfBirthday: int,
dayOfBirthday,
):
self.expressLoveTimestamp = expressLoveTimestamp
self.monthOfBirthday = monthOfBirthday
self.dayOfBirthday = dayOfBirthday
self.meetingTimestamp = meetingTimestamp
class Config:
def __init__(
self,
wxPusher: WxPusherConfig,
weChatWork: WeChatWorkConfig,
weather: WeatherConfig,
lover: LoverConfig,
):
self.wxPusher = wxPusher
self.weChatWork = weChatWork
self.weather = weather
self.lover = lover
def loadConfig(filePath: str) -> Config:
with open(filePath, "r") as file:
configData = yaml.safe_load(file)
wxPusherConfig = WxPusherConfig(
appToken=configData["wxPusher"]["appToken"],
topicIds=configData["wxPusher"]["topicIds"],
)
weChatWorkConfig = WeChatWorkConfig(
webhookKey=configData["wechatWork"]["webhookKey"]
)
weatherConfig = WeatherConfig(
apiKey=configData["weather"]["apiKey"],
city=configData["weather"]["city"],
)
loverConfig = LoverConfig(
expressLoveTimestamp=configData["lover"]["expressLoveTimestamp"],
meetingTimestamp=configData["lover"]["meetingTimestamp"],
monthOfBirthday=configData["lover"]["monthOfBirthday"],
dayOfBirthday=configData["lover"]["dayOfBirthday"],
)
return Config(
wxPusher=wxPusherConfig,
weChatWork=weChatWorkConfig,
weather=weatherConfig,
lover=loverConfig,
)