-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.py
122 lines (93 loc) · 2.72 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import os
from typing import Any, Dict, NoReturn, Union
import requests as r
import yaml
from dataclasses import dataclass, asdict
from typing import Any
dir = os.getcwd()
@dataclass
class UserInfo:
uuid: str
name: str
address: str
@dataclass
class SubscriptionInfo:
plan_name: str
description: str
price: str
duration_months: int
start_date: str
end_date: str
is_active: bool
@dataclass
class APILimits:
daily_limit: int
remaining_calls: int
@dataclass
class GoogleCloudSecurityFile:
type: str
content: Any
@dataclass
class UpdateInfo:
update_available: bool
update_method: str
update_link: str
@dataclass
class Memory:
context_limit: int
@dataclass
class Voice:
url: str
@dataclass
class DeviceConfig:
user_info: UserInfo
subscription_info: SubscriptionInfo
api_limits: APILimits
google_cloud_security_file: GoogleCloudSecurityFile
update_info: UpdateInfo
memory: Memory
voice: Voice
@classmethod
def from_dict(cls, data: dict):
data = data['device_config']
return cls(
user_info=UserInfo(**data['user_info']),
subscription_info=SubscriptionInfo(**data['subscription_info']),
api_limits=APILimits(**data['api_limits']),
google_cloud_security_file=GoogleCloudSecurityFile(**data['google_cloud_security_file']),
update_info=UpdateInfo(**data['update_info']),
memory=Memory(**data['memory']),
voice=Voice(**data['voice'])
)
def to_dict(self):
return {
"user_info": asdict(self.user_info),
"subscription_info": asdict(self.subscription_info),
"api_limits": asdict(self.api_limits),
"google_cloud_security_file": asdict(self.google_cloud_security_file),
"update_info": asdict(self.update_info),
"memory": asdict(self.memory),
"voice": asdict(self.voice)
}
def get_configuration(url: str, device_uuid: Union[str, None]) -> Union[str, DeviceConfig]:
if device_uuid is None:
return "No Device Set Yet!"
url = f"{url}api/j3devices/{device_uuid}/"
response = r.get(url)
return DeviceConfig.from_dict(response.json())
def generate_config(user_id: int) -> NoReturn:
data = {
'user': {
'id': user_id,
}
}
with open(f"{dir}/utilities/data.yaml", 'w') as file:
yaml.safe_dump(data, file, default_flow_style=False)
def read_config() -> Dict[str, Any]:
file: str = f'{dir}/utilities/data.yaml'
with open(file, 'r') as f:
data: Dict[str, Any] = yaml.safe_load(f)
return data
if __name__=='__main__':
# generate_config(123)
print(read_config())