nsarchive 3.0.0a8__tar.gz → 3.0.0b1__tar.gz
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-3.0.0a8 → nsarchive-3.0.0b1}/PKG-INFO +1 -1
- {nsarchive-3.0.0a8 → nsarchive-3.0.0b1}/nsarchive/__init__.py +4 -2
- {nsarchive-3.0.0a8 → nsarchive-3.0.0b1}/nsarchive/interfaces/_entities.py +2 -2
- nsarchive-3.0.0b1/nsarchive/interfaces/_justice.py +122 -0
- {nsarchive-3.0.0a8 → nsarchive-3.0.0b1}/nsarchive/interfaces/_state.py +63 -9
- {nsarchive-3.0.0a8 → nsarchive-3.0.0b1}/nsarchive/models/base.py +5 -2
- {nsarchive-3.0.0a8 → nsarchive-3.0.0b1}/nsarchive/models/economy.py +0 -1
- {nsarchive-3.0.0a8 → nsarchive-3.0.0b1}/nsarchive/models/entities.py +4 -5
- {nsarchive-3.0.0a8 → nsarchive-3.0.0b1}/nsarchive/models/justice.py +2 -2
- {nsarchive-3.0.0a8 → nsarchive-3.0.0b1}/nsarchive/models/republic.py +28 -25
- {nsarchive-3.0.0a8 → nsarchive-3.0.0b1}/nsarchive/models/state.py +21 -5
- {nsarchive-3.0.0a8 → nsarchive-3.0.0b1}/pyproject.toml +1 -1
- nsarchive-3.0.0a8/nsarchive/interfaces/_justice.py +0 -50
- {nsarchive-3.0.0a8 → nsarchive-3.0.0b1}/LICENSE +0 -0
- {nsarchive-3.0.0a8 → nsarchive-3.0.0b1}/README.md +0 -0
- {nsarchive-3.0.0a8 → nsarchive-3.0.0b1}/nsarchive/assets/default_avatar.png +0 -0
- {nsarchive-3.0.0a8 → nsarchive-3.0.0b1}/nsarchive/interfaces/_economy.py +0 -0
- {nsarchive-3.0.0a8 → nsarchive-3.0.0b1}/nsarchive/mandate.py +0 -0
- {nsarchive-3.0.0a8 → nsarchive-3.0.0b1}/nsarchive/models/scale.py +0 -0
- {nsarchive-3.0.0a8 → nsarchive-3.0.0b1}/nsarchive/utils.py +0 -0
@@ -1,8 +1,8 @@
|
|
1
1
|
"""
|
2
2
|
nsarchive - API-wrapper pour récupérer des données liées à Nation.
|
3
3
|
|
4
|
-
Version: 3.0.0-
|
5
|
-
Date de sortie: 2025-08-
|
4
|
+
Version: 3.0.0-beta.1
|
5
|
+
Date de sortie: 2025-08-06
|
6
6
|
License: GPL-3.0
|
7
7
|
Auteur : happex <110610727+okayhappex@users.noreply.github.com>
|
8
8
|
|
@@ -22,6 +22,8 @@ from .models.republic import *
|
|
22
22
|
from .models.state import *
|
23
23
|
from .models.justice import *
|
24
24
|
|
25
|
+
from .models.scale import *
|
26
|
+
|
25
27
|
# Import des interfaces
|
26
28
|
from .models.base import Interface
|
27
29
|
from .interfaces._entities import EntityInterface
|
@@ -83,7 +83,7 @@ class EntityInterface(Interface):
|
|
83
83
|
return
|
84
84
|
|
85
85
|
self._put_in_db(
|
86
|
-
f"/new_model/{_class}?id={
|
86
|
+
f"/new_model/{_class}?id={id}&name={name}&position={position}&zone={zone}",
|
87
87
|
headers = self.default_headers,
|
88
88
|
use_PUT = True
|
89
89
|
)
|
@@ -110,7 +110,7 @@ class EntityInterface(Interface):
|
|
110
110
|
L'entité à supprimer
|
111
111
|
"""
|
112
112
|
|
113
|
-
res = requests.post(f"{entity._url}/delete", headers = self.default_headers
|
113
|
+
res = requests.post(f"{entity._url}/delete", headers = self.default_headers)
|
114
114
|
|
115
115
|
if res.status_code != 200:
|
116
116
|
res.raise_for_status()
|
@@ -0,0 +1,122 @@
|
|
1
|
+
import requests
|
2
|
+
import time
|
3
|
+
|
4
|
+
from ..models.base import *
|
5
|
+
from ..models.justice import *
|
6
|
+
|
7
|
+
class JusticeInterface(Interface):
|
8
|
+
"""
|
9
|
+
Gère les procès, sanctions et signalements.
|
10
|
+
"""
|
11
|
+
|
12
|
+
def __init__(self, url: str, token: str) -> None:
|
13
|
+
super().__init__(url, token)
|
14
|
+
|
15
|
+
"""
|
16
|
+
SIGNALEMENTS
|
17
|
+
"""
|
18
|
+
|
19
|
+
def get_report(self, id: NSID) -> Report:
|
20
|
+
res = requests.get(
|
21
|
+
f"{self.url}/justice/reports/{id}",
|
22
|
+
headers = self.default_headers,
|
23
|
+
)
|
24
|
+
|
25
|
+
if res.status_code != 200:
|
26
|
+
res.raise_for_status()
|
27
|
+
|
28
|
+
report = Report(id)
|
29
|
+
report._load(res.json(), f"{self.url}/justice/reports/{id}", self.default_headers)
|
30
|
+
|
31
|
+
return report
|
32
|
+
|
33
|
+
def submit_report(self, target: NSID, reason: str = None, details: str = None) -> Report:
|
34
|
+
payload = {}
|
35
|
+
if reason: payload['reason'] = reason
|
36
|
+
if details: payload['details'] = details
|
37
|
+
|
38
|
+
res = requests.put(
|
39
|
+
f"{self.url}/justice/submit_report?target={target}",
|
40
|
+
headers = self.default_headers,
|
41
|
+
json = payload
|
42
|
+
)
|
43
|
+
|
44
|
+
if res.status_code != 200:
|
45
|
+
res.raise_for_status()
|
46
|
+
|
47
|
+
report = Report(NSID(res.json()['id']))
|
48
|
+
report._load(res.json(), f"{self.url}/justice/reports/{report.id}", self.default_headers)
|
49
|
+
|
50
|
+
return report
|
51
|
+
|
52
|
+
"""
|
53
|
+
PROCÈS
|
54
|
+
"""
|
55
|
+
|
56
|
+
def get_lawsuit(self, id: NSID) -> Lawsuit:
|
57
|
+
res = requests.get(
|
58
|
+
f"{self.url}/justice/lawsuits/{id}",
|
59
|
+
headers = self.default_headers,
|
60
|
+
)
|
61
|
+
|
62
|
+
if res.status_code != 200:
|
63
|
+
res.raise_for_status()
|
64
|
+
|
65
|
+
lawsuit = Lawsuit(id)
|
66
|
+
lawsuit._load(res.json(), f"{self.url}/justice/lawsuits/{id}", self.default_headers)
|
67
|
+
|
68
|
+
return lawsuit
|
69
|
+
|
70
|
+
def open_lawsuit(self, target: NSID, title: str = None, report: Report = None) -> Lawsuit:
|
71
|
+
payload = {}
|
72
|
+
if title: payload['title'] = title
|
73
|
+
|
74
|
+
res = requests.put(
|
75
|
+
f"{self.url}/justice/open_lawsuit?target={target}{('&report=' + report.id) if report else ''}",
|
76
|
+
headers = self.default_headers,
|
77
|
+
json = payload
|
78
|
+
)
|
79
|
+
|
80
|
+
if res.status_code != 200:
|
81
|
+
res.raise_for_status()
|
82
|
+
|
83
|
+
lawsuit = Lawsuit(NSID(res.json()['id']))
|
84
|
+
lawsuit._load(res.json(), f"{self.url}/justice/lawsuits/{report.id}", self.default_headers)
|
85
|
+
|
86
|
+
return lawsuit
|
87
|
+
|
88
|
+
"""
|
89
|
+
SANCTIONS
|
90
|
+
"""
|
91
|
+
|
92
|
+
def get_sanction(self, id: NSID) -> Sanction:
|
93
|
+
res = requests.get(
|
94
|
+
f"{self.url}/justice/sanctions/{id}",
|
95
|
+
headers = self.default_headers,
|
96
|
+
)
|
97
|
+
|
98
|
+
if res.status_code != 200:
|
99
|
+
res.raise_for_status()
|
100
|
+
|
101
|
+
sanction = Sanction(id)
|
102
|
+
sanction._load(res.json(), f"{self.url}/justice/sanctions/{id}", self.default_headers)
|
103
|
+
|
104
|
+
return sanction
|
105
|
+
|
106
|
+
def add_sanction(self, target: NSID, _type: str, duration: int = None, title: str = None, lawsuit: Lawsuit = None) -> Sanction:
|
107
|
+
payload = {}
|
108
|
+
if title: payload['title'] = title
|
109
|
+
|
110
|
+
res = requests.put(
|
111
|
+
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 ''}",
|
112
|
+
headers = self.default_headers,
|
113
|
+
json = payload
|
114
|
+
)
|
115
|
+
|
116
|
+
if res.status_code != 200:
|
117
|
+
res.raise_for_status()
|
118
|
+
|
119
|
+
sanction = Sanction(NSID(res.json()['id']))
|
120
|
+
sanction._load(res.json(), f"{self.url}/justice/sanctions/{sanction.id}", self.default_headers)
|
121
|
+
|
122
|
+
return sanction
|
@@ -43,7 +43,7 @@ class StateInterface(Interface):
|
|
43
43
|
|
44
44
|
_data = res.json()
|
45
45
|
|
46
|
-
vote = Vote(id
|
46
|
+
vote = Vote(id)
|
47
47
|
vote._load(_data, url = f"{self.url}/votes/{id}", headers = self.default_headers)
|
48
48
|
|
49
49
|
return vote
|
@@ -69,18 +69,70 @@ class StateInterface(Interface):
|
|
69
69
|
if title:
|
70
70
|
payload['title'] = title
|
71
71
|
|
72
|
-
res = requests.put(f"{self.url}/open_vote", headers = self.default_headers, json =
|
72
|
+
res = requests.put(f"{self.url}/open_vote", headers = self.default_headers, json = payload)
|
73
73
|
|
74
74
|
if res.status_code == 200:
|
75
75
|
_data = res.json()
|
76
76
|
|
77
|
-
vote = Vote()
|
77
|
+
vote = Vote(_data['id'])
|
78
78
|
vote._load(_data, url = f"{self.url}/votes/{_data['id']}", headers = self.default_headers)
|
79
|
+
|
80
|
+
return vote
|
79
81
|
else:
|
80
82
|
res.raise_for_status()
|
81
83
|
|
82
84
|
# Aucune possibilité de supprimer un vote
|
83
85
|
|
86
|
+
def get_election(self, id: NSID) -> Election:
|
87
|
+
"""
|
88
|
+
Récupère une élection.
|
89
|
+
|
90
|
+
## Paramètres
|
91
|
+
id: `NSID`\n
|
92
|
+
ID de l'élection.
|
93
|
+
|
94
|
+
## Renvoie
|
95
|
+
- `.Election`
|
96
|
+
"""
|
97
|
+
|
98
|
+
id = NSID(id)
|
99
|
+
res = requests.get(f"{self.url}/elections/{id}", headers = self.default_headers)
|
100
|
+
|
101
|
+
if res.status_code != 200:
|
102
|
+
res.raise_for_status()
|
103
|
+
|
104
|
+
_data = res.json()
|
105
|
+
|
106
|
+
election = Election(id)
|
107
|
+
election._load(_data, url = f"{self.url}/elections/{id}", headers = self.default_headers)
|
108
|
+
|
109
|
+
return election
|
110
|
+
|
111
|
+
def open_election(self, vote: Vote, start: int = None, full: bool = False) -> Election:
|
112
|
+
"""
|
113
|
+
Déclenche une élection dans la base de données.
|
114
|
+
|
115
|
+
## Paramètres
|
116
|
+
- vote: `.Vote`\n
|
117
|
+
Vote associé
|
118
|
+
- start: `int` (optionnel)\n
|
119
|
+
Date de début du vote (timestamp, dure 4 jours)
|
120
|
+
- full: `bool` (optionnel)\n
|
121
|
+
Choix du type d'élections (True = présidentielles, False = législatives)
|
122
|
+
"""
|
123
|
+
|
124
|
+
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 = {})
|
125
|
+
|
126
|
+
if res.status_code == 200:
|
127
|
+
_data = res.json()
|
128
|
+
|
129
|
+
election = Election(_data['id'])
|
130
|
+
election._load(_data, url = f"{self.url}/elections/{_data['id']}", headers = self.default_headers)
|
131
|
+
|
132
|
+
return election
|
133
|
+
else:
|
134
|
+
res.raise_for_status()
|
135
|
+
|
84
136
|
"""
|
85
137
|
PARTIS
|
86
138
|
"""
|
@@ -100,8 +152,8 @@ class StateInterface(Interface):
|
|
100
152
|
id = NSID(id)
|
101
153
|
res = requests.get(f"{self.url}/parties/{id}", headers = self.default_headers)
|
102
154
|
|
103
|
-
if
|
104
|
-
|
155
|
+
if res.status_code != 200:
|
156
|
+
res.raise_for_status()
|
105
157
|
|
106
158
|
_data = res.json()
|
107
159
|
|
@@ -128,15 +180,17 @@ class StateInterface(Interface):
|
|
128
180
|
payload = {
|
129
181
|
"color": color,
|
130
182
|
"motto": motto,
|
131
|
-
"scale": scale
|
183
|
+
"scale": scale if isinstance(scale, dict) else scale._to_dict()
|
132
184
|
}
|
133
185
|
|
134
|
-
res = requests.put(f"{self.url}/register_party?candidate={id}", headers = self.default_headers, json =
|
186
|
+
res = requests.put(f"{self.url}/register_party?candidate={id}", headers = self.default_headers, json = payload)
|
135
187
|
|
136
188
|
if res.status_code == 200:
|
137
189
|
_data = res.json()
|
138
190
|
|
139
|
-
|
140
|
-
|
191
|
+
party = Party(_data['org_id'])
|
192
|
+
party._load(_data, url = f"{self.url}/parties/{_data['org_id']}", headers = self.default_headers)
|
193
|
+
|
194
|
+
return party
|
141
195
|
else:
|
142
196
|
res.raise_for_status()
|
@@ -57,6 +57,10 @@ class Interface:
|
|
57
57
|
"Content-Type": "application/json",
|
58
58
|
}
|
59
59
|
|
60
|
+
return
|
61
|
+
|
62
|
+
# Vérification (ralentit considérablement les requêtes)*
|
63
|
+
|
60
64
|
try:
|
61
65
|
test_res = requests.get(f'{self.url}/ping')
|
62
66
|
|
@@ -138,7 +142,7 @@ class Interface:
|
|
138
142
|
|
139
143
|
return _data
|
140
144
|
|
141
|
-
def _put_in_db(self, endpoint: str, body: dict, headers: dict = None, use_PUT: bool = False) -> None:
|
145
|
+
def _put_in_db(self, endpoint: str, body: dict = {}, headers: dict = None, use_PUT: bool = False) -> None:
|
142
146
|
"""
|
143
147
|
Publie des données JSON dans une table nation-db.
|
144
148
|
|
@@ -162,7 +166,6 @@ class Interface:
|
|
162
166
|
if 200 <= res.status_code < 300:
|
163
167
|
return res.json()
|
164
168
|
else:
|
165
|
-
print(res.text)
|
166
169
|
res.raise_for_status()
|
167
170
|
|
168
171
|
def _delete(self, _class: str, ids: list[NSID]) -> None:
|
@@ -10,10 +10,10 @@ from .. import utils
|
|
10
10
|
|
11
11
|
class Permission:
|
12
12
|
def __init__(self, initial: str = "----"):
|
13
|
-
self.append: bool
|
14
|
-
self.manage: bool
|
15
|
-
self.edit: bool
|
16
|
-
self.read: bool
|
13
|
+
self.append: bool = False
|
14
|
+
self.manage: bool = False
|
15
|
+
self.edit: bool = False
|
16
|
+
self.read: bool = False
|
17
17
|
|
18
18
|
self.load(initial)
|
19
19
|
|
@@ -195,7 +195,6 @@ class Entity:
|
|
195
195
|
if res.status_code == 200:
|
196
196
|
self.additional[key] = value
|
197
197
|
else:
|
198
|
-
print(res.text)
|
199
198
|
res.raise_for_status()
|
200
199
|
|
201
200
|
def unlink(self, key: str) -> None:
|
@@ -60,7 +60,7 @@ class Sanction:
|
|
60
60
|
self.date: int = round(time.time())
|
61
61
|
self.duration: int = 0
|
62
62
|
self.title: str = None
|
63
|
-
self.
|
63
|
+
self.lawsuit: NSID = NSID('0')
|
64
64
|
|
65
65
|
def _load(self, _data: dict, url: str, headers: dict) -> None:
|
66
66
|
self._url = url
|
@@ -72,7 +72,7 @@ class Sanction:
|
|
72
72
|
self.date = _data['date']
|
73
73
|
self.duration = _data['duration']
|
74
74
|
self.title = _data['title']
|
75
|
-
self.
|
75
|
+
self.lawsuit = NSID(_data['lawsuit'])
|
76
76
|
|
77
77
|
class Lawsuit:
|
78
78
|
def __init__(self, id: NSID):
|
@@ -1,3 +1,4 @@
|
|
1
|
+
import json
|
1
2
|
import requests
|
2
3
|
import time
|
3
4
|
|
@@ -18,10 +19,19 @@ class VoteOption:
|
|
18
19
|
Nombre de sympathisants pour cette option
|
19
20
|
"""
|
20
21
|
|
21
|
-
def __init__(self,
|
22
|
-
self.
|
23
|
-
self.
|
24
|
-
|
22
|
+
def __init__(self, title: str, count: int = 0):
|
23
|
+
self.title: str = title
|
24
|
+
self.count: int = count
|
25
|
+
|
26
|
+
def __repr__(self) -> dict:
|
27
|
+
return json.dumps({
|
28
|
+
'title': self.title,
|
29
|
+
'count': self.count
|
30
|
+
})
|
31
|
+
|
32
|
+
def _load(self, _data: dict):
|
33
|
+
self.title = str(_data['title'])
|
34
|
+
self.count = int(_data['count'])
|
25
35
|
|
26
36
|
class Vote:
|
27
37
|
"""
|
@@ -32,7 +42,7 @@ class Vote:
|
|
32
42
|
Identifiant du vote
|
33
43
|
- title: `str`\n
|
34
44
|
Titre du vote
|
35
|
-
- options:
|
45
|
+
- options: dict[str, .VoteOption]\n
|
36
46
|
Liste des choix disponibles
|
37
47
|
- author: `NSID`\n
|
38
48
|
Identifiant de l'auteur du vote
|
@@ -53,31 +63,29 @@ class Vote:
|
|
53
63
|
self.startDate: int = round(time.time())
|
54
64
|
self.endDate: int = 0
|
55
65
|
|
56
|
-
self.options:
|
66
|
+
self.options: dict[str, VoteOption] = {}
|
57
67
|
|
58
68
|
def _load(self, _data: dict, url: str, headers: dict) -> None:
|
59
|
-
self._url = url
|
69
|
+
self._url = url
|
60
70
|
self._headers = headers
|
61
71
|
|
62
72
|
self.id = NSID(_data['id'])
|
63
73
|
self.title = _data['title']
|
64
|
-
self.author = _data['
|
74
|
+
self.author = _data['author']
|
65
75
|
|
66
|
-
self.startDate = _data['
|
67
|
-
self.endDate = _data['
|
76
|
+
self.startDate = _data['start']
|
77
|
+
self.endDate = _data['end']
|
68
78
|
|
69
|
-
self.options =
|
79
|
+
self.options = {}
|
70
80
|
|
71
|
-
for opt in _data['options']:
|
72
|
-
option = VoteOption(opt
|
73
|
-
option.count = opt["count"]
|
81
|
+
for _opt_id, opt in _data['options'].items():
|
82
|
+
option = VoteOption(*tuple(opt.values()))
|
74
83
|
|
75
|
-
self.options
|
84
|
+
self.options[_opt_id] = option
|
76
85
|
|
77
86
|
def get(self, id: str) -> VoteOption:
|
78
|
-
|
79
|
-
|
80
|
-
return opt
|
87
|
+
if id in self.options.keys():
|
88
|
+
return self.options[id]
|
81
89
|
else:
|
82
90
|
raise ValueError(f"Option {id} not found in vote {self.id}")
|
83
91
|
|
@@ -86,15 +94,10 @@ class Vote:
|
|
86
94
|
Ajoute un vote à l'option spécifiée
|
87
95
|
"""
|
88
96
|
|
89
|
-
res = requests.post(f"{self._url}/vote?
|
97
|
+
res = requests.post(f"{self._url}/vote?option={id}", headers = self._headers)
|
90
98
|
|
91
99
|
if res.status_code == 200:
|
92
|
-
|
93
|
-
if opt.id == id:
|
94
|
-
opt.count += 1
|
95
|
-
break
|
96
|
-
else:
|
97
|
-
raise ValueError(f"Option {id} not found in vote {self.id}")
|
100
|
+
self.get(id).count += 1
|
98
101
|
else:
|
99
102
|
res.raise_for_status()
|
100
103
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
from __future__ import annotations
|
2
|
+
|
1
3
|
import requests
|
2
4
|
|
3
5
|
from .base import NSID
|
@@ -13,7 +15,7 @@ class Party:
|
|
13
15
|
self.color: int = 0x000000
|
14
16
|
self.motto: str = None
|
15
17
|
self.scale: dict = {}
|
16
|
-
self.
|
18
|
+
self.last_election: int = None
|
17
19
|
|
18
20
|
def _load(self, _data: dict, url: str = None, headers: dict = None):
|
19
21
|
self._url = url
|
@@ -24,7 +26,10 @@ class Party:
|
|
24
26
|
self.color = _data['color']
|
25
27
|
self.motto = _data['motto']
|
26
28
|
self.scale = _data['politiscales']
|
27
|
-
self.
|
29
|
+
self.last_election = _data['last_election']
|
30
|
+
|
31
|
+
def cancel_candidacy(self, election: Election):
|
32
|
+
election.cancel_candidacy()
|
28
33
|
|
29
34
|
class Election:
|
30
35
|
def __init__(self, id: NSID):
|
@@ -35,17 +40,28 @@ class Election:
|
|
35
40
|
self.type: str = 'full' # Partial = législatives, full = totales
|
36
41
|
self.vote: Vote = None
|
37
42
|
|
38
|
-
self.add_vote = self.vote.add_vote
|
39
|
-
self.close = self.vote.close
|
40
|
-
|
41
43
|
def _load(self, _data: dict, url: str = None, headers: str = None):
|
42
44
|
self._url = url
|
43
45
|
self._headers = headers
|
44
46
|
|
45
47
|
self.id = _data['id']
|
46
48
|
self.type = _data['type']
|
49
|
+
|
50
|
+
self.vote = Vote(_data['vote']['id'])
|
47
51
|
self.vote._load(_data['vote'], url, headers)
|
48
52
|
|
53
|
+
def close(self):
|
54
|
+
if self.vote:
|
55
|
+
self.vote.close()
|
56
|
+
else:
|
57
|
+
return
|
58
|
+
|
59
|
+
def add_vote(self, id: str):
|
60
|
+
if self.vote:
|
61
|
+
self.vote.add_vote(id)
|
62
|
+
else:
|
63
|
+
return
|
64
|
+
|
49
65
|
def submit_candidacy(self):
|
50
66
|
res = requests.put(f"{self._url}/submit")
|
51
67
|
|
@@ -1,50 +0,0 @@
|
|
1
|
-
import requests
|
2
|
-
import time
|
3
|
-
|
4
|
-
from ..models.base import *
|
5
|
-
from ..models.justice import *
|
6
|
-
|
7
|
-
class JusticeInterface(Interface):
|
8
|
-
"""
|
9
|
-
Gère les procès, sanctions et signalements.
|
10
|
-
"""
|
11
|
-
|
12
|
-
def __init__(self, url: str, token: str) -> None:
|
13
|
-
super().__init__(url, token)
|
14
|
-
|
15
|
-
"""
|
16
|
-
SIGNALEMENTS
|
17
|
-
"""
|
18
|
-
|
19
|
-
def get_report(self, id: NSID) -> Report:
|
20
|
-
res = requests.get(
|
21
|
-
f"{self.url}/justice/reports/{id}",
|
22
|
-
headers = self.default_headers,
|
23
|
-
)
|
24
|
-
|
25
|
-
if res.status_code != 200:
|
26
|
-
res.raise_for_status()
|
27
|
-
|
28
|
-
report = Report(id)
|
29
|
-
report._load(res.json(), f"{self.url}/justice/reports/{id}", self.default_headers)
|
30
|
-
|
31
|
-
return report
|
32
|
-
|
33
|
-
def submit_report(self, target: NSID, reason: str = None, details: str = None) -> Report:
|
34
|
-
payload = {}
|
35
|
-
if reason: payload['reason'] = reason
|
36
|
-
if details: payload['details'] = details
|
37
|
-
|
38
|
-
res = requests.put(
|
39
|
-
f"{self.url}/justice/submit_report?target={target}",
|
40
|
-
headers = self.default_headers,
|
41
|
-
json = payload
|
42
|
-
)
|
43
|
-
|
44
|
-
if res.status_code != 200:
|
45
|
-
res.raise_for_status()
|
46
|
-
|
47
|
-
report = Report(NSID(res.json()['id']))
|
48
|
-
report._load(res.json(), f"{self.url}/justice/reports/{report.id}", self.default_headers)
|
49
|
-
|
50
|
-
return report
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|