nsarchive 3.0.0a8__py3-none-any.whl → 3.0.0b2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- nsarchive/__init__.py +6 -2
- nsarchive/errors/__init__.py +1 -0
- nsarchive/errors/_globals.py +29 -0
- nsarchive/interfaces/_economy.py +0 -252
- nsarchive/interfaces/_entities.py +101 -15
- nsarchive/interfaces/_justice.py +232 -8
- nsarchive/interfaces/_state.py +221 -24
- nsarchive/mandate.py +21 -2
- nsarchive/models/base.py +113 -71
- nsarchive/models/economy.py +80 -152
- nsarchive/models/entities.py +309 -73
- nsarchive/models/justice.py +25 -4
- nsarchive/models/republic.py +72 -29
- nsarchive/models/state.py +64 -9
- nsarchive-3.0.0b2.dist-info/METADATA +90 -0
- nsarchive-3.0.0b2.dist-info/RECORD +21 -0
- nsarchive-3.0.0a8.dist-info/METADATA +0 -21
- nsarchive-3.0.0a8.dist-info/RECORD +0 -19
- {nsarchive-3.0.0a8.dist-info → nsarchive-3.0.0b2.dist-info}/LICENSE +0 -0
- {nsarchive-3.0.0a8.dist-info → nsarchive-3.0.0b2.dist-info}/WHEEL +0 -0
nsarchive/interfaces/_justice.py
CHANGED
@@ -22,11 +22,36 @@ class JusticeInterface(Interface):
|
|
22
22
|
headers = self.default_headers,
|
23
23
|
)
|
24
24
|
|
25
|
-
|
26
|
-
|
25
|
+
|
26
|
+
# ERREURS
|
27
|
+
|
28
|
+
if 500 <= res.status_code < 600:
|
29
|
+
raise errors.globals.ServerDownError()
|
30
|
+
|
31
|
+
_data = res.json()
|
32
|
+
|
33
|
+
if res.status_code == 400:
|
34
|
+
if _data['message'] == "MissingParam":
|
35
|
+
raise errors.globals.MissingParamError(f"Missing parameter '{_data['param']}'.")
|
36
|
+
elif _data['message'] == "InvalidParam":
|
37
|
+
raise errors.globals.InvalidParamError(f"Invalid parameter '{_data['param']}'.")
|
38
|
+
elif _data['message'] == "InvalidToken":
|
39
|
+
raise errors.globals.AuthError("Token is not valid.")
|
40
|
+
|
41
|
+
elif res.status_code == 401:
|
42
|
+
raise errors.globals.AuthError(_data['message'])
|
43
|
+
|
44
|
+
elif res.status_code == 403:
|
45
|
+
raise errors.globals.PermissionError(_data['message'])
|
46
|
+
|
47
|
+
elif res.status_code == 404:
|
48
|
+
return
|
49
|
+
|
50
|
+
|
51
|
+
# TRAITEMENT
|
27
52
|
|
28
53
|
report = Report(id)
|
29
|
-
report._load(
|
54
|
+
report._load(_data, f"{self.url}/justice/reports/{id}", self.default_headers)
|
30
55
|
|
31
56
|
return report
|
32
57
|
|
@@ -41,10 +66,209 @@ class JusticeInterface(Interface):
|
|
41
66
|
json = payload
|
42
67
|
)
|
43
68
|
|
44
|
-
if res.status_code != 200:
|
45
|
-
res.raise_for_status()
|
46
69
|
|
47
|
-
|
48
|
-
|
70
|
+
# ERREURS
|
71
|
+
|
72
|
+
if 500 <= res.status_code < 600:
|
73
|
+
raise errors.globals.ServerDownError()
|
74
|
+
|
75
|
+
_data = res.json()
|
76
|
+
|
77
|
+
if res.status_code == 400:
|
78
|
+
if _data['message'] == "MissingParam":
|
79
|
+
raise errors.globals.MissingParamError(f"Missing parameter '{_data['param']}'.")
|
80
|
+
elif _data['message'] == "InvalidParam":
|
81
|
+
raise errors.globals.InvalidParamError(f"Invalid parameter '{_data['param']}'.")
|
82
|
+
elif _data['message'] == "InvalidToken":
|
83
|
+
raise errors.globals.AuthError("Token is not valid.")
|
84
|
+
|
85
|
+
elif res.status_code == 401:
|
86
|
+
raise errors.globals.AuthError(_data['message'])
|
87
|
+
|
88
|
+
elif res.status_code == 403:
|
89
|
+
raise errors.globals.PermissionError(_data['message'])
|
90
|
+
|
91
|
+
elif res.status_code == 404:
|
92
|
+
return
|
93
|
+
|
94
|
+
|
95
|
+
# TRAITEMENT
|
96
|
+
|
97
|
+
report = Report(NSID(_data['id']))
|
98
|
+
report._load(_data, f"{self.url}/justice/reports/{report.id}", self.default_headers)
|
99
|
+
|
100
|
+
return report
|
101
|
+
|
102
|
+
|
103
|
+
"""
|
104
|
+
PROCÈS
|
105
|
+
"""
|
106
|
+
|
107
|
+
def get_lawsuit(self, id: NSID) -> Lawsuit:
|
108
|
+
res = requests.get(
|
109
|
+
f"{self.url}/justice/lawsuits/{id}",
|
110
|
+
headers = self.default_headers,
|
111
|
+
)
|
112
|
+
|
113
|
+
|
114
|
+
# ERREURS
|
115
|
+
|
116
|
+
if 500 <= res.status_code < 600:
|
117
|
+
raise errors.globals.ServerDownError()
|
118
|
+
|
119
|
+
_data = res.json()
|
120
|
+
|
121
|
+
if res.status_code == 400:
|
122
|
+
if _data['message'] == "MissingParam":
|
123
|
+
raise errors.globals.MissingParamError(f"Missing parameter '{_data['param']}'.")
|
124
|
+
elif _data['message'] == "InvalidParam":
|
125
|
+
raise errors.globals.InvalidParamError(f"Invalid parameter '{_data['param']}'.")
|
126
|
+
elif _data['message'] == "InvalidToken":
|
127
|
+
raise errors.globals.AuthError("Token is not valid.")
|
128
|
+
|
129
|
+
elif res.status_code == 401:
|
130
|
+
raise errors.globals.AuthError(_data['message'])
|
131
|
+
|
132
|
+
elif res.status_code == 403:
|
133
|
+
raise errors.globals.PermissionError(_data['message'])
|
134
|
+
|
135
|
+
elif res.status_code == 404:
|
136
|
+
return
|
137
|
+
|
138
|
+
|
139
|
+
# TRAITEMENT
|
140
|
+
|
141
|
+
lawsuit = Lawsuit(id)
|
142
|
+
lawsuit._load(_data, f"{self.url}/justice/lawsuits/{id}", self.default_headers)
|
143
|
+
|
144
|
+
return lawsuit
|
145
|
+
|
146
|
+
def open_lawsuit(self, target: NSID, title: str = None, report: Report = None) -> Lawsuit:
|
147
|
+
payload = {}
|
148
|
+
if title: payload['title'] = title
|
149
|
+
|
150
|
+
res = requests.put(
|
151
|
+
f"{self.url}/justice/open_lawsuit?target={target}{('&report=' + report.id) if report else ''}",
|
152
|
+
headers = self.default_headers,
|
153
|
+
json = payload
|
154
|
+
)
|
155
|
+
|
156
|
+
|
157
|
+
# ERREURS
|
158
|
+
|
159
|
+
if 500 <= res.status_code < 600:
|
160
|
+
raise errors.globals.ServerDownError()
|
161
|
+
|
162
|
+
_data = res.json()
|
163
|
+
|
164
|
+
if res.status_code == 400:
|
165
|
+
if _data['message'] == "MissingParam":
|
166
|
+
raise errors.globals.MissingParamError(f"Missing parameter '{_data['param']}'.")
|
167
|
+
elif _data['message'] == "InvalidParam":
|
168
|
+
raise errors.globals.InvalidParamError(f"Invalid parameter '{_data['param']}'.")
|
169
|
+
elif _data['message'] == "InvalidToken":
|
170
|
+
raise errors.globals.AuthError("Token is not valid.")
|
171
|
+
|
172
|
+
elif res.status_code == 401:
|
173
|
+
raise errors.globals.AuthError(_data['message'])
|
174
|
+
|
175
|
+
elif res.status_code == 403:
|
176
|
+
raise errors.globals.PermissionError(_data['message'])
|
177
|
+
|
178
|
+
elif res.status_code == 404:
|
179
|
+
return
|
180
|
+
|
181
|
+
|
182
|
+
# TRAITEMENT
|
183
|
+
|
184
|
+
lawsuit = Lawsuit(NSID(_data['id']))
|
185
|
+
lawsuit._load(_data, f"{self.url}/justice/lawsuits/{report.id}", self.default_headers)
|
186
|
+
|
187
|
+
return lawsuit
|
188
|
+
|
189
|
+
|
190
|
+
"""
|
191
|
+
SANCTIONS
|
192
|
+
"""
|
193
|
+
|
194
|
+
def get_sanction(self, id: NSID) -> Sanction:
|
195
|
+
res = requests.get(
|
196
|
+
f"{self.url}/justice/sanctions/{id}",
|
197
|
+
headers = self.default_headers,
|
198
|
+
)
|
199
|
+
|
200
|
+
|
201
|
+
# ERREURS
|
202
|
+
|
203
|
+
if 500 <= res.status_code < 600:
|
204
|
+
raise errors.globals.ServerDownError()
|
205
|
+
|
206
|
+
_data = res.json()
|
207
|
+
|
208
|
+
if res.status_code == 400:
|
209
|
+
if _data['message'] == "MissingParam":
|
210
|
+
raise errors.globals.MissingParamError(f"Missing parameter '{_data['param']}'.")
|
211
|
+
elif _data['message'] == "InvalidParam":
|
212
|
+
raise errors.globals.InvalidParamError(f"Invalid parameter '{_data['param']}'.")
|
213
|
+
elif _data['message'] == "InvalidToken":
|
214
|
+
raise errors.globals.AuthError("Token is not valid.")
|
215
|
+
|
216
|
+
elif res.status_code == 401:
|
217
|
+
raise errors.globals.AuthError(_data['message'])
|
218
|
+
|
219
|
+
elif res.status_code == 403:
|
220
|
+
raise errors.globals.PermissionError(_data['message'])
|
221
|
+
|
222
|
+
elif res.status_code == 404:
|
223
|
+
return
|
224
|
+
|
225
|
+
|
226
|
+
# TRAITEMENT
|
227
|
+
|
228
|
+
sanction = Sanction(id)
|
229
|
+
sanction._load(_data, f"{self.url}/justice/sanctions/{id}", self.default_headers)
|
230
|
+
|
231
|
+
return sanction
|
232
|
+
|
233
|
+
def add_sanction(self, target: NSID, _type: str, duration: int = None, title: str = None, lawsuit: Lawsuit = None) -> Sanction:
|
234
|
+
payload = {}
|
235
|
+
if title: payload['title'] = title
|
236
|
+
|
237
|
+
res = requests.put(
|
238
|
+
f"{self.url}/justice/add_sanction?type={_type}&target={target}&date={str(round(time.time()))}{('&duration=' + str(duration)) if duration else ''}{('&case=' + lawsuit.id) if lawsuit else ''}",
|
239
|
+
headers = self.default_headers,
|
240
|
+
json = payload
|
241
|
+
)
|
242
|
+
|
243
|
+
|
244
|
+
# ERREURS
|
245
|
+
|
246
|
+
if 500 <= res.status_code < 600:
|
247
|
+
raise errors.globals.ServerDownError()
|
248
|
+
|
249
|
+
_data = res.json()
|
250
|
+
|
251
|
+
if res.status_code == 400:
|
252
|
+
if _data['message'] == "MissingParam":
|
253
|
+
raise errors.globals.MissingParamError(f"Missing parameter '{_data['param']}'.")
|
254
|
+
elif _data['message'] == "InvalidParam":
|
255
|
+
raise errors.globals.InvalidParamError(f"Invalid parameter '{_data['param']}'.")
|
256
|
+
elif _data['message'] == "InvalidToken":
|
257
|
+
raise errors.globals.AuthError("Token is not valid.")
|
258
|
+
|
259
|
+
elif res.status_code == 401:
|
260
|
+
raise errors.globals.AuthError(_data['message'])
|
261
|
+
|
262
|
+
elif res.status_code == 403:
|
263
|
+
raise errors.globals.PermissionError(_data['message'])
|
264
|
+
|
265
|
+
elif res.status_code == 404:
|
266
|
+
return
|
267
|
+
|
268
|
+
|
269
|
+
# TRAITEMENT
|
270
|
+
|
271
|
+
sanction = Sanction(NSID(_data['id']))
|
272
|
+
sanction._load(_data, f"{self.url}/justice/sanctions/{sanction.id}", self.default_headers)
|
49
273
|
|
50
|
-
return
|
274
|
+
return sanction
|
nsarchive/interfaces/_state.py
CHANGED
@@ -38,17 +38,40 @@ class StateInterface(Interface):
|
|
38
38
|
id = NSID(id)
|
39
39
|
res = requests.get(f"{self.url}/votes/{id}", headers = self.default_headers)
|
40
40
|
|
41
|
-
|
42
|
-
|
41
|
+
|
42
|
+
# ERREURS
|
43
|
+
|
44
|
+
if 500 <= res.status_code < 600:
|
45
|
+
raise errors.globals.ServerDownError()
|
43
46
|
|
44
47
|
_data = res.json()
|
45
48
|
|
46
|
-
|
49
|
+
if res.status_code == 400:
|
50
|
+
if _data['message'] == "MissingParam":
|
51
|
+
raise errors.globals.MissingParamError(f"Missing parameter '{_data['param']}'.")
|
52
|
+
elif _data['message'] == "InvalidParam":
|
53
|
+
raise errors.globals.InvalidParamError(f"Invalid parameter '{_data['param']}'.")
|
54
|
+
elif _data['message'] == "InvalidToken":
|
55
|
+
raise errors.globals.AuthError("Token is not valid.")
|
56
|
+
|
57
|
+
elif res.status_code == 401:
|
58
|
+
raise errors.globals.AuthError(_data['message'])
|
59
|
+
|
60
|
+
elif res.status_code == 403:
|
61
|
+
raise errors.globals.PermissionError(_data['message'])
|
62
|
+
|
63
|
+
elif res.status_code == 404:
|
64
|
+
return
|
65
|
+
|
66
|
+
|
67
|
+
# TRAITEMENT
|
68
|
+
|
69
|
+
vote = Vote(id)
|
47
70
|
vote._load(_data, url = f"{self.url}/votes/{id}", headers = self.default_headers)
|
48
71
|
|
49
72
|
return vote
|
50
73
|
|
51
|
-
def open_vote(self, title: str = None, options: list[dict] = [], end: int =
|
74
|
+
def open_vote(self, title: str = None, options: list[dict] = [], start: int = None, end: int = None) -> Vote:
|
52
75
|
"""
|
53
76
|
Déclenche un vote dans la base de données.
|
54
77
|
|
@@ -57,30 +80,152 @@ class StateInterface(Interface):
|
|
57
80
|
Titre du vote
|
58
81
|
- options: list[dict]\n
|
59
82
|
Liste des choix disponibles
|
60
|
-
-
|
83
|
+
- start: `int` (optionnel)\n
|
84
|
+
Début du vote (timestamp)
|
85
|
+
- end: `int` (optionnel)\n
|
61
86
|
Fin du vote (timestamp)
|
62
87
|
"""
|
63
88
|
|
64
89
|
payload = {
|
65
90
|
"options": options,
|
66
|
-
"end_date": end
|
67
91
|
}
|
68
92
|
|
69
93
|
if title:
|
70
94
|
payload['title'] = title
|
71
95
|
|
72
|
-
res = requests.put(f"{self.url}/open_vote", headers = self.default_headers, json =
|
96
|
+
res = requests.put(f"{self.url}/open_vote?a=b{('&start=' + str(start)) if start else ''}{('&end=' + str(end)) if end else ''}", headers = self.default_headers, json = payload)
|
97
|
+
|
73
98
|
|
74
|
-
|
75
|
-
_data = res.json()
|
99
|
+
# ERREURS
|
76
100
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
101
|
+
if 500 <= res.status_code < 600:
|
102
|
+
raise errors.globals.ServerDownError()
|
103
|
+
|
104
|
+
_data = res.json()
|
105
|
+
|
106
|
+
if res.status_code == 400:
|
107
|
+
if _data['message'] == "MissingParam":
|
108
|
+
raise errors.globals.MissingParamError(f"Missing parameter '{_data['param']}'.")
|
109
|
+
elif _data['message'] == "InvalidParam":
|
110
|
+
raise errors.globals.InvalidParamError(f"Invalid parameter '{_data['param']}'.")
|
111
|
+
elif _data['message'] == "InvalidToken":
|
112
|
+
raise errors.globals.AuthError("Token is not valid.")
|
113
|
+
|
114
|
+
elif res.status_code == 401:
|
115
|
+
raise errors.globals.AuthError(_data['message'])
|
116
|
+
|
117
|
+
elif res.status_code == 403:
|
118
|
+
raise errors.globals.PermissionError(_data['message'])
|
119
|
+
|
120
|
+
elif res.status_code == 404:
|
121
|
+
return
|
122
|
+
|
123
|
+
|
124
|
+
# TRAITEMENT
|
125
|
+
|
126
|
+
vote = Vote(_data['id'])
|
127
|
+
vote._load(_data, url = f"{self.url}/votes/{_data['id']}", headers = self.default_headers)
|
128
|
+
|
129
|
+
return vote
|
81
130
|
|
82
131
|
# Aucune possibilité de supprimer un vote
|
83
132
|
|
133
|
+
def get_election(self, id: NSID) -> Election:
|
134
|
+
"""
|
135
|
+
Récupère une élection.
|
136
|
+
|
137
|
+
## Paramètres
|
138
|
+
id: `NSID`\n
|
139
|
+
ID de l'élection.
|
140
|
+
|
141
|
+
## Renvoie
|
142
|
+
- `.Election`
|
143
|
+
"""
|
144
|
+
|
145
|
+
id = NSID(id)
|
146
|
+
res = requests.get(f"{self.url}/elections/{id}", headers = self.default_headers)
|
147
|
+
|
148
|
+
|
149
|
+
# ERREURS
|
150
|
+
|
151
|
+
if 500 <= res.status_code < 600:
|
152
|
+
raise errors.globals.ServerDownError()
|
153
|
+
|
154
|
+
_data = res.json()
|
155
|
+
|
156
|
+
if res.status_code == 400:
|
157
|
+
if _data['message'] == "MissingParam":
|
158
|
+
raise errors.globals.MissingParamError(f"Missing parameter '{_data['param']}'.")
|
159
|
+
elif _data['message'] == "InvalidParam":
|
160
|
+
raise errors.globals.InvalidParamError(f"Invalid parameter '{_data['param']}'.")
|
161
|
+
elif _data['message'] == "InvalidToken":
|
162
|
+
raise errors.globals.AuthError("Token is not valid.")
|
163
|
+
|
164
|
+
elif res.status_code == 401:
|
165
|
+
raise errors.globals.AuthError(_data['message'])
|
166
|
+
|
167
|
+
elif res.status_code == 403:
|
168
|
+
raise errors.globals.PermissionError(_data['message'])
|
169
|
+
|
170
|
+
elif res.status_code == 404:
|
171
|
+
return
|
172
|
+
|
173
|
+
|
174
|
+
# TRAITEMENT
|
175
|
+
|
176
|
+
election = Election(id)
|
177
|
+
election._load(_data, url = f"{self.url}/elections/{id}", headers = self.default_headers)
|
178
|
+
|
179
|
+
return election
|
180
|
+
|
181
|
+
def open_election(self, vote: Vote, start: int = None, full: bool = False) -> Election:
|
182
|
+
"""
|
183
|
+
Déclenche une élection dans la base de données.
|
184
|
+
|
185
|
+
## Paramètres
|
186
|
+
- vote: `.Vote`\n
|
187
|
+
Vote associé
|
188
|
+
- start: `int` (optionnel)\n
|
189
|
+
Date de début du vote (timestamp, dure 4 jours)
|
190
|
+
- full: `bool` (optionnel)\n
|
191
|
+
Choix du type d'élections (True = présidentielles, False = législatives)
|
192
|
+
"""
|
193
|
+
|
194
|
+
res = requests.put(f"{self.url}/open_election?vote={vote.id}&type={'full' if full else 'partial'}{('&date=' + str(start)) if start else ''}", headers = self.default_headers, json = {})
|
195
|
+
|
196
|
+
|
197
|
+
# ERREURS
|
198
|
+
|
199
|
+
if 500 <= res.status_code < 600:
|
200
|
+
raise errors.globals.ServerDownError()
|
201
|
+
|
202
|
+
_data = res.json()
|
203
|
+
|
204
|
+
if res.status_code == 400:
|
205
|
+
if _data['message'] == "MissingParam":
|
206
|
+
raise errors.globals.MissingParamError(f"Missing parameter '{_data['param']}'.")
|
207
|
+
elif _data['message'] == "InvalidParam":
|
208
|
+
raise errors.globals.InvalidParamError(f"Invalid parameter '{_data['param']}'.")
|
209
|
+
elif _data['message'] == "InvalidToken":
|
210
|
+
raise errors.globals.AuthError("Token is not valid.")
|
211
|
+
|
212
|
+
elif res.status_code == 401:
|
213
|
+
raise errors.globals.AuthError(_data['message'])
|
214
|
+
|
215
|
+
elif res.status_code == 403:
|
216
|
+
raise errors.globals.PermissionError(_data['message'])
|
217
|
+
|
218
|
+
elif res.status_code == 404:
|
219
|
+
return
|
220
|
+
|
221
|
+
|
222
|
+
# TRAITEMENT
|
223
|
+
|
224
|
+
election = Election(_data['id'])
|
225
|
+
election._load(_data, url = f"{self.url}/elections/{_data['id']}", headers = self.default_headers)
|
226
|
+
|
227
|
+
return election
|
228
|
+
|
84
229
|
"""
|
85
230
|
PARTIS
|
86
231
|
"""
|
@@ -100,11 +245,34 @@ class StateInterface(Interface):
|
|
100
245
|
id = NSID(id)
|
101
246
|
res = requests.get(f"{self.url}/parties/{id}", headers = self.default_headers)
|
102
247
|
|
103
|
-
|
104
|
-
|
248
|
+
|
249
|
+
# ERREURS
|
250
|
+
|
251
|
+
if 500 <= res.status_code < 600:
|
252
|
+
raise errors.globals.ServerDownError()
|
105
253
|
|
106
254
|
_data = res.json()
|
107
255
|
|
256
|
+
if res.status_code == 400:
|
257
|
+
if _data['message'] == "MissingParam":
|
258
|
+
raise errors.globals.MissingParamError(f"Missing parameter '{_data['param']}'.")
|
259
|
+
elif _data['message'] == "InvalidParam":
|
260
|
+
raise errors.globals.InvalidParamError(f"Invalid parameter '{_data['param']}'.")
|
261
|
+
elif _data['message'] == "InvalidToken":
|
262
|
+
raise errors.globals.AuthError("Token is not valid.")
|
263
|
+
|
264
|
+
elif res.status_code == 401:
|
265
|
+
raise errors.globals.AuthError(_data['message'])
|
266
|
+
|
267
|
+
elif res.status_code == 403:
|
268
|
+
raise errors.globals.PermissionError(_data['message'])
|
269
|
+
|
270
|
+
elif res.status_code == 404:
|
271
|
+
return
|
272
|
+
|
273
|
+
|
274
|
+
# TRAITEMENT
|
275
|
+
|
108
276
|
party = Party(id)
|
109
277
|
party._load(_data, url = f"{self.url}/parties/{id}", headers = self.default_headers)
|
110
278
|
|
@@ -121,22 +289,51 @@ class StateInterface(Interface):
|
|
121
289
|
Couleur du parti
|
122
290
|
- motto: `str, optional`\n
|
123
291
|
Devise du parti
|
124
|
-
-
|
292
|
+
- scale: `.Scale`\n
|
125
293
|
Résultats du parti au test Politiscales
|
126
294
|
"""
|
127
295
|
|
128
296
|
payload = {
|
129
297
|
"color": color,
|
130
298
|
"motto": motto,
|
131
|
-
"scale":
|
299
|
+
"scale": {}
|
132
300
|
}
|
133
301
|
|
134
|
-
|
302
|
+
params = {
|
303
|
+
"candidate": id
|
304
|
+
}
|
305
|
+
|
306
|
+
res = requests.put(f"{self.url}/register_party", headers = self.default_headers, params = params, json = payload)
|
307
|
+
|
308
|
+
|
309
|
+
# ERREURS
|
310
|
+
|
311
|
+
if 500 <= res.status_code < 600:
|
312
|
+
raise errors.globals.ServerDownError()
|
313
|
+
|
314
|
+
_data = res.json()
|
315
|
+
|
316
|
+
if res.status_code == 400:
|
317
|
+
if _data['message'] == "MissingParam":
|
318
|
+
raise errors.globals.MissingParamError(f"Missing parameter '{_data['param']}'.")
|
319
|
+
elif _data['message'] == "InvalidParam":
|
320
|
+
raise errors.globals.InvalidParamError(f"Invalid parameter '{_data['param']}'.")
|
321
|
+
elif _data['message'] == "InvalidToken":
|
322
|
+
raise errors.globals.AuthError("Token is not valid.")
|
323
|
+
|
324
|
+
elif res.status_code == 401:
|
325
|
+
raise errors.globals.AuthError(_data['message'])
|
326
|
+
|
327
|
+
elif res.status_code == 403:
|
328
|
+
raise errors.globals.PermissionError(_data['message'])
|
329
|
+
|
330
|
+
elif res.status_code == 404:
|
331
|
+
return
|
332
|
+
|
333
|
+
|
334
|
+
# TRAITEMENT
|
135
335
|
|
136
|
-
|
137
|
-
|
336
|
+
party = Party(_data['org_id'])
|
337
|
+
party._load(_data, url = f"{self.url}/parties/{_data['org_id']}", headers = self.default_headers)
|
138
338
|
|
139
|
-
|
140
|
-
vote._load(_data, url = f"{self.url}/votes/{_data['id']}", headers = self.default_headers)
|
141
|
-
else:
|
142
|
-
res.raise_for_status()
|
339
|
+
return party
|
nsarchive/mandate.py
CHANGED
@@ -5,7 +5,7 @@ EPOCH = 1577833200 # 1er Janvier 2020
|
|
5
5
|
PATIENTAGE_DATE = 1725141600 # 1er Septembre 2024
|
6
6
|
OPEN_DATE = 1756677600 # 1er Septembre 2025
|
7
7
|
|
8
|
-
MANDATE_DURATION = 2419200
|
8
|
+
MANDATE_DURATION = 2419200 # 28 jours
|
9
9
|
|
10
10
|
def get_cycle(ts: int = round(time.time())):
|
11
11
|
if EPOCH <= ts < PATIENTAGE_DATE:
|
@@ -47,4 +47,23 @@ def get_phase(ts: int = round(time.time())) -> str:
|
|
47
47
|
return 'elections' # Élections législatives et présidentielles
|
48
48
|
|
49
49
|
else:
|
50
|
-
raise ValueError(f"Idk what happened but it seems that {day} is greater than 55...")
|
50
|
+
raise ValueError(f"Idk what happened but it seems that {day} is greater than 55...")
|
51
|
+
|
52
|
+
|
53
|
+
def next_election(type: str = 'partial') -> int:
|
54
|
+
if get_cycle() == 1:
|
55
|
+
return PATIENTAGE_DATE
|
56
|
+
elif get_cycle() == 2:
|
57
|
+
return OPEN_DATE
|
58
|
+
else:
|
59
|
+
if type == 'partial':
|
60
|
+
ts = OPEN_DATE + get_cycle() * MANDATE_DURATION
|
61
|
+
elif type == 'full':
|
62
|
+
ts = OPEN_DATE + get_cycle() * MANDATE_DURATION
|
63
|
+
|
64
|
+
if get_cycle() % 2 == 1:
|
65
|
+
ts += 28 * 86400
|
66
|
+
|
67
|
+
ts = round(ts / 86400) * 86400
|
68
|
+
|
69
|
+
return ts
|