nsarchive 3.0.0a7__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.
Files changed (24) hide show
  1. {nsarchive-3.0.0a7 → nsarchive-3.0.0b1}/PKG-INFO +3 -2
  2. nsarchive-3.0.0b1/nsarchive/__init__.py +32 -0
  3. {nsarchive-3.0.0a7/nsarchive/instances → nsarchive-3.0.0b1/nsarchive/interfaces}/_economy.py +15 -30
  4. nsarchive-3.0.0b1/nsarchive/interfaces/_entities.py +206 -0
  5. nsarchive-3.0.0b1/nsarchive/interfaces/_justice.py +122 -0
  6. nsarchive-3.0.0b1/nsarchive/interfaces/_state.py +196 -0
  7. nsarchive-3.0.0b1/nsarchive/mandate.py +50 -0
  8. {nsarchive-3.0.0a7/nsarchive/cls → nsarchive-3.0.0b1/nsarchive/models}/base.py +28 -7
  9. {nsarchive-3.0.0a7/nsarchive/cls → nsarchive-3.0.0b1/nsarchive/models}/economy.py +34 -14
  10. {nsarchive-3.0.0a7/nsarchive/cls → nsarchive-3.0.0b1/nsarchive/models}/entities.py +143 -77
  11. nsarchive-3.0.0b1/nsarchive/models/justice.py +108 -0
  12. nsarchive-3.0.0b1/nsarchive/models/republic.py +128 -0
  13. nsarchive-3.0.0b1/nsarchive/models/scale.py +23 -0
  14. nsarchive-3.0.0b1/nsarchive/models/state.py +75 -0
  15. {nsarchive-3.0.0a7 → nsarchive-3.0.0b1}/pyproject.toml +1 -1
  16. nsarchive-3.0.0a7/nsarchive/__init__.py +0 -25
  17. nsarchive-3.0.0a7/nsarchive/cls/archives.py +0 -93
  18. nsarchive-3.0.0a7/nsarchive/cls/republic.py +0 -149
  19. nsarchive-3.0.0a7/nsarchive/instances/_entities.py +0 -281
  20. nsarchive-3.0.0a7/nsarchive/instances/_republic.py +0 -339
  21. {nsarchive-3.0.0a7 → nsarchive-3.0.0b1}/LICENSE +0 -0
  22. {nsarchive-3.0.0a7 → nsarchive-3.0.0b1}/README.md +0 -0
  23. {nsarchive-3.0.0a7 → nsarchive-3.0.0b1}/nsarchive/assets/default_avatar.png +0 -0
  24. {nsarchive-3.0.0a7 → nsarchive-3.0.0b1}/nsarchive/utils.py +0 -0
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.3
2
2
  Name: nsarchive
3
- Version: 3.0.0a7
3
+ Version: 3.0.0b1
4
4
  Summary: API-wrapper pour récupérer des données liées à Nation
5
5
  License: GPL-3.0
6
6
  Author: happex
@@ -11,6 +11,7 @@ Classifier: Programming Language :: Python :: 3
11
11
  Classifier: Programming Language :: Python :: 3.10
12
12
  Classifier: Programming Language :: Python :: 3.11
13
13
  Classifier: Programming Language :: Python :: 3.12
14
+ Classifier: Programming Language :: Python :: 3.13
14
15
  Requires-Dist: pillow (>=10.4,<11.0)
15
16
  Requires-Dist: requests (>=2.31,<3.0)
16
17
  Description-Content-Type: text/markdown
@@ -0,0 +1,32 @@
1
+ """
2
+ nsarchive - API-wrapper pour récupérer des données liées à Nation.
3
+
4
+ Version: 3.0.0-beta.1
5
+ Date de sortie: 2025-08-06
6
+ License: GPL-3.0
7
+ Auteur : happex <110610727+okayhappex@users.noreply.github.com>
8
+
9
+ Dependencies:
10
+ - Python ^3.10
11
+ - pillow ^10.4
12
+
13
+ Le fichier README.md fournit des détails supplémentaires pour l'utilisation.
14
+ """
15
+
16
+ # Import des types
17
+ from .models.base import NSID
18
+ from .models.entities import *
19
+ from .models.economy import *
20
+
21
+ from .models.republic import *
22
+ from .models.state import *
23
+ from .models.justice import *
24
+
25
+ from .models.scale import *
26
+
27
+ # Import des interfaces
28
+ from .models.base import Interface
29
+ from .interfaces._entities import EntityInterface
30
+ from .interfaces._economy import EconomyInterface
31
+ from .interfaces._state import StateInterface
32
+ from .interfaces._justice import JusticeInterface
@@ -1,13 +1,12 @@
1
1
  import time
2
2
 
3
- from ..cls.base import *
4
- from ..cls.archives import *
5
- from ..cls.economy import *
3
+ from ..models.base import *
4
+ from ..models.economy import *
6
5
 
7
- from ..cls import economy # Pour les default_headers
6
+ from ..models import economy # Pour les default_headers
8
7
 
9
- class EconomyInstance(Instance):
10
- """Indisponible dans cette version."""
8
+ class EconomyInterface(Interface):
9
+ """Interface qui vous permettra d'interagir avec les comptes en banque et les transactions économiques."""
11
10
 
12
11
  def __init__(self, url: str, token: str) -> None:
13
12
  super().__init__(url, token)
@@ -43,9 +42,7 @@ class EconomyInstance(Instance):
43
42
  return None
44
43
 
45
44
  account = BankAccount(id)
46
- account._url = f"{self.url}/bank/accounts/{account.id}"
47
-
48
- account._load(_data)
45
+ account._load(_data, self.url, self.default_headers)
49
46
 
50
47
  return account
51
48
 
@@ -107,9 +104,7 @@ class EconomyInstance(Instance):
107
104
  account = BankAccount(_acc["owner_id"])
108
105
 
109
106
  account.id = NSID(_acc['id'])
110
- account._url = f"{self.url}/bank/accounts/{account.id}"
111
-
112
- account._load(_acc)
107
+ account._load(_acc, self.url, self.default_headers)
113
108
 
114
109
  res.append(account)
115
110
 
@@ -144,9 +139,7 @@ class EconomyInstance(Instance):
144
139
  return None
145
140
 
146
141
  inventory = Inventory(id)
147
- inventory._url = f"{self.url}/bank/inventories/{inventory.id}"
148
-
149
- inventory._load(_data)
142
+ inventory._load(_data, self.url, self.default_headers)
150
143
 
151
144
  return inventory
152
145
 
@@ -201,9 +194,7 @@ class EconomyInstance(Instance):
201
194
  inventory = Inventory(_inv["owner_id"])
202
195
 
203
196
  inventory.id = NSID(_inv['id'])
204
- inventory._url = f"{self.url}/bank/inventories/{inventory.id}"
205
-
206
- inventory._load(_inv)
197
+ inventory._load(_inv, self.url, self.default_headers)
207
198
 
208
199
  res.append(inventory)
209
200
 
@@ -238,10 +229,9 @@ class EconomyInstance(Instance):
238
229
  return None
239
230
 
240
231
  item = Item()
241
- item.id = id
242
- item._url = f"{self.url}/marketplace/items/{item.id}"
243
232
 
244
- item._load(_data)
233
+ item.id = id
234
+ item._load(_data, self.url, self.default_headers)
245
235
 
246
236
  return item
247
237
 
@@ -294,9 +284,7 @@ class EconomyInstance(Instance):
294
284
  item = Item()
295
285
 
296
286
  item.id = NSID(_item['id'])
297
- item._url = f"{self.url}/marketplace/items/{item.id}"
298
-
299
- item._load(_item)
287
+ item._load(_item, self.url, self.default_headers)
300
288
 
301
289
  res.append(item)
302
290
 
@@ -332,10 +320,9 @@ class EconomyInstance(Instance):
332
320
  return None
333
321
 
334
322
  sale = Sale()
335
- sale.id = id
336
- sale._url = f"{self.url}/marketplace/sales/{sale.id}"
337
323
 
338
- sale._load(_data)
324
+ sale.id = id
325
+ sale._load(_data, self.url, self.default_headers)
339
326
 
340
327
  return sale
341
328
 
@@ -369,9 +356,7 @@ class EconomyInstance(Instance):
369
356
  sale = Sale()
370
357
 
371
358
  sale.id = NSID(_sale['id'])
372
- sale._url = f"{self.url}/marketplace/sales/{sale.id}"
373
-
374
- sale._load(_sale)
359
+ sale._load(_sale, self.url, self.default_headers)
375
360
 
376
361
  res.append(sale)
377
362
 
@@ -0,0 +1,206 @@
1
+ from ..models.base import *
2
+ from ..models.entities import *
3
+
4
+ from ..models import entities # Pour les default_headers
5
+
6
+ class EntityInterface(Interface):
7
+ """
8
+ Interface qui vous permettra d'interagir avec les profils des membres ainsi que les différents métiers et secteurs d'activité.
9
+
10
+ ## Informations disponibles
11
+ - Profil des membres et des entreprises: `.User | .Organization | .Entity`
12
+ - Participation d'un membre à différent votes: `.User | .Organization | .Entity`
13
+ - Appartenance et permissions d'un membre dans un groupe: `.GroupMember.MemberPermissions`
14
+ - Position légale et permissions d'une entité: `.Position.Permissions`
15
+ - Sanctions et modifications d'une entité: `.Action[ .AdminAction | .Sanction ]`
16
+ """
17
+
18
+ def __init__(self, url: str, token: str = None) -> None:
19
+ super().__init__(url, token)
20
+
21
+ """
22
+ ---- ENTITÉS ----
23
+ """
24
+
25
+ def get_entity(self, id: NSID, _class: str = None) -> User | Organization | Entity:
26
+ """
27
+ Fonction permettant de récupérer le profil public d'une entité.\n
28
+
29
+ ## Paramètres
30
+ id: `NSID`
31
+ ID héxadécimal de l'entité à récupérer
32
+ _class: `str`
33
+ Classe du modèle à prendre (`.User` ou `.Organization`)
34
+
35
+ ## Renvoie
36
+ - `.User` dans le cas où l'entité choisie est un membre
37
+ - `.Organization` dans le cas où c'est un groupe
38
+ - `.Entity` dans le cas où c'est indéterminé
39
+ """
40
+
41
+ id = NSID(id)
42
+
43
+ if _class == "user":
44
+ _data = self._get_by_ID('individuals', id)
45
+ elif _class == "group":
46
+ _data = self._get_by_ID('organizations', id)
47
+ else:
48
+ _data = self._get_by_ID('entities', id)
49
+
50
+ if _data is None: # ID inexistant chez les entités
51
+ return None
52
+
53
+ if _data['_class'] == 'individuals':
54
+ entity = User(id)
55
+ elif _data['_class'] == 'organizations':
56
+ entity = Organization(id)
57
+ else:
58
+ entity = Entity(id)
59
+
60
+ entity._load(_data, self.url, self.default_headers)
61
+
62
+ return entity
63
+
64
+ def create_entity(self, id: NSID, name: str, _class: str, position: str = 'membre', zone: int = 10):
65
+ """
66
+ Fonction permettant de créer ou modifier une entité.
67
+
68
+ ## Paramètres
69
+ - id (`NSID`): Identifiant NSID
70
+ - name (`str`): Nom d'usage
71
+ - _class (`"user"` ou `"group"`): Type de l'entité
72
+ - position (`str`, optionnel): ID de la position civile
73
+ - zone (`int`, optionnel): ID de la zone civile
74
+ """
75
+
76
+ id = NSID(id)
77
+
78
+ if _class in ('group', 'organization'):
79
+ _class = 'organizations'
80
+ elif _class in ('user', 'individual'):
81
+ _class = 'individuals'
82
+ else:
83
+ return
84
+
85
+ self._put_in_db(
86
+ f"/new_model/{_class}?id={id}&name={name}&position={position}&zone={zone}",
87
+ headers = self.default_headers,
88
+ use_PUT = True
89
+ )
90
+
91
+ entity = self.get_entity(id)
92
+
93
+ if _class == "individuals":
94
+ entity._url = f"{self.url}/model/individuals/{id}"
95
+ elif isinstance(entity, Organization):
96
+ entity._url = f"{self.url}/model/organizations/{id}"
97
+ entity.avatar_url = f"{entity._url}/avatar"
98
+ else:
99
+ entity._url = f"{self.url}/model/entities/{id}"
100
+
101
+ return entity
102
+
103
+
104
+ def delete_entity(self, entity: Entity):
105
+ """
106
+ Fonction permettant de supprimer le profil d'une entité
107
+
108
+ ## Paramètres
109
+ entity: `.Entity`\n
110
+ L'entité à supprimer
111
+ """
112
+
113
+ res = requests.post(f"{entity._url}/delete", headers = self.default_headers)
114
+
115
+ if res.status_code != 200:
116
+ res.raise_for_status()
117
+
118
+ def fetch_entities(self, **query: typing.Any) -> list[ Entity | User | Organization ]:
119
+ """
120
+ Récupère une liste d'entités en fonction d'une requête.
121
+
122
+ ## Paramètres
123
+ query: `**dict`\n
124
+ La requête pour filtrer les entités.
125
+
126
+ ## Renvoie
127
+ - `list[.Entity | .User | .Organization]`
128
+ """
129
+
130
+ if "_class" in query.keys():
131
+ if query["_class"] == "individuals":
132
+ del query["_class"]
133
+ _res = self.fetch('individuals', **query)
134
+ elif query["_class"] == "organizations":
135
+ del query["_class"]
136
+ _res = self.fetch('organizations', **query)
137
+ else:
138
+ del query["_class"]
139
+ _res = self.fetch('entities', **query)
140
+ else:
141
+ _res = self.fetch('entities', **query)
142
+
143
+ res = []
144
+
145
+ for _entity in _res:
146
+ if _entity is None: continue
147
+
148
+ if _entity['_class'] == 'individuals':
149
+ entity = User(_entity["id"])
150
+ elif _entity['_class'] == 'organizations':
151
+ entity = Organization(_entity["id"])
152
+ else:
153
+ entity = Entity(_entity["id"])
154
+
155
+ entity._load(_entity, self.url, self.default_headers)
156
+
157
+ res.append(entity)
158
+
159
+ return res
160
+
161
+
162
+
163
+ def get_position(self, id: str) -> Position:
164
+ """
165
+ Récupère une position légale (métier, domaine professionnel).
166
+
167
+ ## Paramètres
168
+ id: `str`\n
169
+ ID de la position (SENSIBLE À LA CASSE !)
170
+
171
+ ## Renvoie
172
+ - `.Position`
173
+ """
174
+
175
+ _data = self._get_by_ID('positions', id)
176
+
177
+ if _data is None:
178
+ return None
179
+
180
+ position = Position(id)
181
+ position._load(_data, self.url, self.default_headers)
182
+
183
+ return position
184
+
185
+ def fetch_positions(self, **query: typing.Any) -> list[Position]:
186
+ """
187
+ Récupère une liste de positions en fonction d'une requête.
188
+
189
+ ## Paramètres
190
+ query: `**dict`\n
191
+ La requête pour filtrer les positions.
192
+
193
+ ## Renvoie
194
+ - `list[.Position]`
195
+ """
196
+
197
+ _res = self.fetch('positions', **query)
198
+ res = []
199
+
200
+ for _data in _res:
201
+ pos = Position()
202
+ pos._load(_data, self.url, self.default_headers)
203
+
204
+ res.append(pos)
205
+
206
+ return res
@@ -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
@@ -0,0 +1,196 @@
1
+ import time
2
+
3
+ from ..models.base import *
4
+ from ..models.republic import *
5
+ from ..models.state import *
6
+ from ..models.scale import *
7
+
8
+ class StateInterface(Interface):
9
+ """
10
+ Gère les interactions avec les votes et les officiers.
11
+
12
+ ## Informations
13
+ - Liste des partis enregistrés: `.Party`
14
+ - Liste des élections: `.Election`
15
+ - Liste des officiers et candidats: `.Officer | .Candidate`
16
+ - Résultats des votes: `.Vote`
17
+ """
18
+
19
+ def __init__(self, url: str, token: str) -> None:
20
+ super().__init__(url, token)
21
+
22
+ """
23
+ ---- VOTES ----
24
+ """
25
+
26
+ def get_vote(self, id: NSID) -> Vote:
27
+ """
28
+ Récupère un vote.
29
+
30
+ ## Paramètres
31
+ id: `NSID`\n
32
+ ID du vote.
33
+
34
+ ## Renvoie
35
+ - `.Vote`
36
+ """
37
+
38
+ id = NSID(id)
39
+ res = requests.get(f"{self.url}/votes/{id}", headers = self.default_headers)
40
+
41
+ if not res:
42
+ return None
43
+
44
+ _data = res.json()
45
+
46
+ vote = Vote(id)
47
+ vote._load(_data, url = f"{self.url}/votes/{id}", headers = self.default_headers)
48
+
49
+ return vote
50
+
51
+ def open_vote(self, title: str = None, options: list[dict] = [], end: int = 0) -> Vote:
52
+ """
53
+ Déclenche un vote dans la base de données.
54
+
55
+ ## Paramètres
56
+ - title: `str`\n
57
+ Titre du vote
58
+ - options: list[dict]\n
59
+ Liste des choix disponibles
60
+ - end: `int`\n
61
+ Fin du vote (timestamp)
62
+ """
63
+
64
+ payload = {
65
+ "options": options,
66
+ "end_date": end
67
+ }
68
+
69
+ if title:
70
+ payload['title'] = title
71
+
72
+ res = requests.put(f"{self.url}/open_vote", headers = self.default_headers, json = payload)
73
+
74
+ if res.status_code == 200:
75
+ _data = res.json()
76
+
77
+ vote = Vote(_data['id'])
78
+ vote._load(_data, url = f"{self.url}/votes/{_data['id']}", headers = self.default_headers)
79
+
80
+ return vote
81
+ else:
82
+ res.raise_for_status()
83
+
84
+ # Aucune possibilité de supprimer un vote
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
+
136
+ """
137
+ PARTIS
138
+ """
139
+
140
+ def get_party(self, id: NSID) -> Party:
141
+ """
142
+ Récupère un parti politique.
143
+
144
+ ## Paramètres
145
+ id: `NSID`\n
146
+ ID du parti.
147
+
148
+ ## Renvoie
149
+ - `.Party`
150
+ """
151
+
152
+ id = NSID(id)
153
+ res = requests.get(f"{self.url}/parties/{id}", headers = self.default_headers)
154
+
155
+ if res.status_code != 200:
156
+ res.raise_for_status()
157
+
158
+ _data = res.json()
159
+
160
+ party = Party(id)
161
+ party._load(_data, url = f"{self.url}/parties/{id}", headers = self.default_headers)
162
+
163
+ return party
164
+
165
+ def register_party(self, id: NSID, color: int, motto: str = None, scale: dict | Scale = {}) -> Party:
166
+ """
167
+ Enregistre un nouveau parti pour que ses députés puissent s'y présenter.
168
+
169
+ ## Paramètres
170
+ - id: `NSID`\n
171
+ ID de l'entreprise à laquelle correspond le parti
172
+ - color: `int`\n
173
+ Couleur du parti
174
+ - motto: `str, optional`\n
175
+ Devise du parti
176
+ - politiscales: `.Scale`\n
177
+ Résultats du parti au test Politiscales
178
+ """
179
+
180
+ payload = {
181
+ "color": color,
182
+ "motto": motto,
183
+ "scale": scale if isinstance(scale, dict) else scale._to_dict()
184
+ }
185
+
186
+ res = requests.put(f"{self.url}/register_party?candidate={id}", headers = self.default_headers, json = payload)
187
+
188
+ if res.status_code == 200:
189
+ _data = res.json()
190
+
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
195
+ else:
196
+ res.raise_for_status()