nsarchive 3.0.0a8__py3-none-any.whl → 3.0.0b1__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 CHANGED
@@ -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-alpha.8
5
- Date de sortie: 2025-08-04
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={urllib.parse.quote(id)}&name={urllib.parse.quote(name)}&position={urllib.parse.quote(position)}&zone={urllib.parse.quote(zone)}",
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()
@@ -47,4 +47,76 @@ class JusticeInterface(Interface):
47
47
  report = Report(NSID(res.json()['id']))
48
48
  report._load(res.json(), f"{self.url}/justice/reports/{report.id}", self.default_headers)
49
49
 
50
- return report
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, _data['title'])
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 = _data)
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 not res:
104
- return None
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 = _data)
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
- vote = Vote()
140
- vote._load(_data, url = f"{self.url}/votes/{_data['id']}", headers = self.default_headers)
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()
nsarchive/models/base.py CHANGED
@@ -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:
@@ -65,7 +65,6 @@ class BankAccount:
65
65
  if res.status_code == 200:
66
66
  self.frozen = frozen
67
67
  else:
68
- print(res.text)
69
68
  res.raise_for_status()
70
69
 
71
70
  def flag(self, flagged: bool = True, reason: str = None) -> 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.case: NSID = NSID('0')
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.case = NSID(_data['case'])
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, id: str, title: str = None, count: int = 0):
22
- self.id = id
23
- self.title = title if title else id
24
- self.count = count
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: list[.VoteOption]\n
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: list[VoteOption] = []
66
+ self.options: dict[str, VoteOption] = {}
57
67
 
58
68
  def _load(self, _data: dict, url: str, headers: dict) -> None:
59
- self._url = url + '/votes/' + _data['id']
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['author_id']
74
+ self.author = _data['author']
65
75
 
66
- self.startDate = _data['start_date']
67
- self.endDate = _data['end_date']
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["id"], opt["title"])
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.append(option)
84
+ self.options[_opt_id] = option
76
85
 
77
86
  def get(self, id: str) -> VoteOption:
78
- for opt in self.options:
79
- if opt.id == id:
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?choice={id}", headers = self._headers)
97
+ res = requests.post(f"{self._url}/vote?option={id}", headers = self._headers)
90
98
 
91
99
  if res.status_code == 200:
92
- for opt in self.options:
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
 
nsarchive/models/state.py CHANGED
@@ -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.last_elected: int = None
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.last_elected = _data['last_elected']
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,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: nsarchive
3
- Version: 3.0.0a8
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
@@ -0,0 +1,19 @@
1
+ nsarchive/__init__.py,sha256=Sh9eQ1alsA-fnFr3AHeMEQ5PZ1r4h_XtCBii3FlkUDs,853
2
+ nsarchive/assets/default_avatar.png,sha256=n-4vG_WPke8LvbY3ZU6oA-H-OtRoIu7woKnRq9DCIlI,51764
3
+ nsarchive/interfaces/_economy.py,sha256=54TpYKRw07HIryd3EDifA9Hs3s6O7aHcrtV4P8qY0QY,9348
4
+ nsarchive/interfaces/_entities.py,sha256=9iSw_AAMmdh7VY8BgQkRoZ0RIMsi7ZYYLB3_PJXMbOU,6399
5
+ nsarchive/interfaces/_justice.py,sha256=AOuPLgja1D1_MU6oll5JOdb0yjLknd7QIdxyStDNhBM,3708
6
+ nsarchive/interfaces/_state.py,sha256=7cGYnkjUXLnkGnZiYNfhq4QraZ_lqMXdlBriV-SUQng,5515
7
+ nsarchive/mandate.py,sha256=U0RE9Gpr3XawSWyr99X__GUoiwJAwKbOP4v_I2Z97Oc,1609
8
+ nsarchive/models/base.py,sha256=UBpM4B1nOPJCPJmPAkbumGYxGxBtQUY7omh8uEczsCc,8763
9
+ nsarchive/models/economy.py,sha256=GD1G2fOyIZxquC7F6Rawy0V1gmXN0keTh-r4xvcGl6Y,7681
10
+ nsarchive/models/entities.py,sha256=UP3jFS-KDIER8-K1EVdjgCge7qeCtJ3106XBNrhDKLE,17429
11
+ nsarchive/models/justice.py,sha256=RuFmPi6mK-8APc-_WSPz4bYfnC46WYwdEnzGsZcdXDw,3420
12
+ nsarchive/models/republic.py,sha256=hZA9XB-jHQjscBzuk7vfB_CjtU2Yb8AFM3TxFM6RF5k,3260
13
+ nsarchive/models/scale.py,sha256=ukh6wiE4mBcqbqtAC9GvCyTVUnwYUp3jla03Nohnsck,751
14
+ nsarchive/models/state.py,sha256=gxxUu-E6t2tEx70vXT5XQ17JppP2JKpk4MWclWoqUSM,1963
15
+ nsarchive/utils.py,sha256=L37Dm8aO0Sm3FDLPf2tP6fo-1lodDq7JIz-WXttNuJg,684
16
+ nsarchive-3.0.0b1.dist-info/LICENSE,sha256=aFLFZg6LEJFpTlNQ8su3__jw4GfV-xWBmC1cePkKZVw,35802
17
+ nsarchive-3.0.0b1.dist-info/METADATA,sha256=gQ9hFbAZ6cf_xXRJnx1h36io5qfafhGJ1s6lH4zng6c,746
18
+ nsarchive-3.0.0b1.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
19
+ nsarchive-3.0.0b1.dist-info/RECORD,,
@@ -1,19 +0,0 @@
1
- nsarchive/__init__.py,sha256=QyFBy5jIe_cJBpTdNj-q_0nLqLfKoGC7m4D8LjCOpQo,823
2
- nsarchive/assets/default_avatar.png,sha256=n-4vG_WPke8LvbY3ZU6oA-H-OtRoIu7woKnRq9DCIlI,51764
3
- nsarchive/interfaces/_economy.py,sha256=54TpYKRw07HIryd3EDifA9Hs3s6O7aHcrtV4P8qY0QY,9348
4
- nsarchive/interfaces/_entities.py,sha256=FSFHtM2ygDGLWMU32zJej-BO2rVbrMYhxaJoXymdHMA,6480
5
- nsarchive/interfaces/_justice.py,sha256=perTRdhI7g7he2hcJ0kW9g8plt_BSHD8rMcR6FzBqG0,1382
6
- nsarchive/interfaces/_state.py,sha256=OCpSx4i_lqkJQ2FWZpFBKp2HIlwVCqsQOG42d8yCmO0,3747
7
- nsarchive/mandate.py,sha256=U0RE9Gpr3XawSWyr99X__GUoiwJAwKbOP4v_I2Z97Oc,1609
8
- nsarchive/models/base.py,sha256=yu04x3-vwPeda5R1DviHsDjP-44vIGZIpriX_c6czIY,8698
9
- nsarchive/models/economy.py,sha256=TA6QewVdhNYn4VuhsGaCkjSlJojDO59sgfLtCE5mgPE,7710
10
- nsarchive/models/entities.py,sha256=W6kXMsBlrIAfSOerRJEzVNtufHdNjXv2QNvXDwnVfTM,17426
11
- nsarchive/models/justice.py,sha256=kr3g3UqA7eexVqjiWSaT_O49NIJ84g_7z8vCXjTrLhA,3411
12
- nsarchive/models/republic.py,sha256=7KfNCzj6mNe389csKhHuTFqlAT60HeikhQbMWwPwnBk,3292
13
- nsarchive/models/scale.py,sha256=ukh6wiE4mBcqbqtAC9GvCyTVUnwYUp3jla03Nohnsck,751
14
- nsarchive/models/state.py,sha256=iP13C4IP0e0P-f1rkPwzTVe6j_QVM-ZRMDILlVVEUU8,1622
15
- nsarchive/utils.py,sha256=L37Dm8aO0Sm3FDLPf2tP6fo-1lodDq7JIz-WXttNuJg,684
16
- nsarchive-3.0.0a8.dist-info/LICENSE,sha256=aFLFZg6LEJFpTlNQ8su3__jw4GfV-xWBmC1cePkKZVw,35802
17
- nsarchive-3.0.0a8.dist-info/METADATA,sha256=A9g3R24rXcBYUFS2xVqptNBY9DwdyxOagaL7NyGyvG0,746
18
- nsarchive-3.0.0a8.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
19
- nsarchive-3.0.0a8.dist-info/RECORD,,