nsarchive 3.0.0a7__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.
@@ -1,339 +0,0 @@
1
- import time
2
-
3
- from ..cls.base import *
4
- from ..cls.archives import *
5
- from ..cls.republic import *
6
-
7
-
8
- class RepublicInstance(Instance):
9
- """
10
- *INDISPONIBLE DANS CETTE VERSION.*\n
11
- Gère les interactions avec les votes, les archives de la république, et les fonctionnaires.
12
-
13
- ## Informations
14
- - Résultats des votes et procès: `.Vote | .Referendum | .Lawsuit`
15
- - Différentes institutions: `.State | .Administration | .Government | .Assembly | .Court | .PoliceForces`
16
- - Occupants des différents rôles et historique de leurs actions: `.Official`
17
- """
18
-
19
- def __init__(self, url: str, token: str) -> None:
20
- super().__init__(url, token)
21
-
22
- """
23
- ---- VOTES & REFERENDUMS ----
24
- """
25
-
26
- def get_vote(self, id: NSID) -> Vote | Referendum | Lawsuit:
27
- """
28
- *INDISPONIBLE DANS CETTE VERSION.*\n
29
- Récupère un vote spécifique.
30
-
31
- ## Paramètres
32
- id: `NSID`\n
33
- ID du vote.
34
-
35
- ## Renvoie
36
- - `.Vote | .Referendum | .Lawsuit`
37
- """
38
-
39
- return Vote(NSID(id), "Vote Inconnu") # Provisoire
40
-
41
- id = NSID(id)
42
- _data = self._get_by_ID('votes', id)
43
-
44
- if not _data: # Pas dans les votes -> peut-être dans les procès
45
- _data = self._get_by_ID('lawsuits', id)
46
-
47
- if not _data: # Le vote n'existe juste pas
48
- return None
49
- elif '_type' not in _data.keys(): # Le vote est un procès
50
- _data['_type'] = "lawsuit"
51
-
52
- if _data['_type'] == 'vote':
53
- vote = Vote(id, _data['title'])
54
- elif _data['_type'] == 'referendum':
55
- vote = Referendum(id, _data['title'])
56
- vote.choices = []
57
- elif _data['_type'] == 'lawsuit':
58
- vote = Lawsuit(id, _data['title'])
59
- vote.choices = []
60
- else:
61
- vote = Vote('0', 'Unknown Vote')
62
-
63
- vote.author = _data['author_id']
64
- vote.startDate = _data['start_date']
65
- vote.endDate = _data['end_date']
66
-
67
- for opt in _data['choices']:
68
- option = VoteOption(opt["id"], opt["title"])
69
- option.count = opt["count"]
70
-
71
- vote.choices.append(option)
72
-
73
- return vote
74
-
75
- def save_vote(self, vote: Vote | Referendum | Lawsuit):
76
- """
77
- *INDISPONIBLE DANS CETTE VERSION.*\n
78
- Sauvegarde un vote dans la base de données.
79
-
80
- ## Paramètres
81
- - vote: `.Vote`\n
82
- Vote à sauvegarder
83
- """
84
-
85
- return # Provisoire
86
-
87
- vote.id = NSID(vote.id)
88
-
89
- _data = {
90
- '_type':'vote' if type(vote) == Vote else\
91
- 'referendum' if type(vote) == Referendum else\
92
- 'lawsuit' if type(vote) == Lawsuit else\
93
- 'unknown',
94
- 'id': NSID(vote.id),
95
- 'title': vote.title,
96
- 'author_id': NSID(vote.author),
97
- 'start_date': vote.startDate,
98
- 'end_date': vote.endDate,
99
- 'choices': [ opt.__dict__ for opt in vote.choices ]
100
- }
101
-
102
- if type(vote) == Lawsuit:
103
- del _data['_type']
104
- self._put_in_db('lawsuits', _data)
105
- else:
106
- self._put_in_db('votes', _data)
107
-
108
- # Aucune possibilité de supprimer un vote
109
-
110
- """
111
- ---- INSTITUTION & MANDAT ----
112
- """
113
-
114
- def get_official(self, id: NSID, current_mandate: bool = True) -> Official:
115
- """
116
- *INDISPONIBLE DANS CETTE VERSION.*\n
117
- Récupère les informations d'un fonctionnaire (mandats, contributions).
118
-
119
- ## Paramètres
120
- id: `NSID`\n
121
- ID du fonctionnaire.
122
- current_mandate: `bool`\n
123
- Indique si l'on doit récupérer le mandat actuel ou les anciens mandats.
124
-
125
- ## Renvoie
126
- - `.Official`
127
- """
128
-
129
- return Official(NSID(id)) # Provisoire
130
-
131
- id = NSID(id)
132
-
133
- base = 'mandate' if current_mandate else 'archives'
134
-
135
- _contributions = self.fetch(base, author = id, _type = 'contrib')
136
- _mandates = self.fetch(base, target = id, _type = 'election') +\
137
- self.fetch(base, target = id, _type = 'promotion')
138
-
139
- user = Official(id)
140
- for mandate in _mandates:
141
- if mandate['details']['position'].startswith('MIN'):
142
- mandate['details']['position'] = 'MIN'
143
-
144
- try:
145
- user.mandates[mandate['details']['position']] += 1
146
- except KeyError:
147
- user.mandates[mandate['details']['position']] = 1
148
-
149
- for contrib in _contributions:
150
- try:
151
- user.contributions[contrib['action']] += 1
152
- except KeyError:
153
- user.contributions[contrib['action']] = 1
154
-
155
- return user
156
-
157
- def get_institutions(self) -> State:
158
- """
159
- *INDISPONIBLE DANS CETTE VERSION.*\n
160
- Récupère l'état actuel des institutions de la république.
161
- """
162
-
163
- return State()
164
-
165
- admin = Administration()
166
- gov = Government(Official('0'))
167
- assembly = Assembly()
168
- court = Court()
169
- police_forces = PoliceForces()
170
-
171
- _get_position: list[dict] = lambda pos : self._select_from_db('functions', 'id', pos)[0]['users']
172
-
173
- admin.members = [ self.get_official(user) for user in _get_position('ADMIN') ]
174
- admin.president = self.get_official(0xF7DB60DD1C4300A) # happex (remplace Kheops pour l'instant)
175
-
176
- gov.president = self.get_official(0x0)
177
-
178
- minister = lambda code : self.get_official(_get_position(f'MIN_{code}')[0])
179
- gov.prime_minister = minister('PRIM')
180
- gov.economy_minister = minister('ECO')
181
- gov.inner_minister = minister('INN')
182
- gov.press_minister = minister('AUD')
183
- gov.justice_minister = minister('JUS')
184
- gov.outer_minister = minister('OUT')
185
-
186
- assembly.president = self.get_official(_get_position('PRE_AS')[0])
187
- assembly.members = [ self.get_official(user) for user in _get_position('REPR') ]
188
-
189
- court.president = gov.justice_minister
190
- court.members = [ self.get_official(user) for user in _get_position('JUDGE') ]
191
-
192
- police_forces.president = gov.inner_minister
193
- police_forces.members = [ self.get_official(user) for user in _get_position('POLICE') ]
194
-
195
- instits = State()
196
- instits.administration = admin
197
- instits.government = gov
198
- instits.court = court
199
- instits.assembly = assembly
200
- instits.police = police_forces
201
-
202
- return instits
203
-
204
- def update_institutions(self, institutions: State):
205
- """
206
- *INDISPONIBLE DANS CETTE VERSION.*\n
207
- Fonction communément appelée après un vote législatif ou une nomination.\n
208
- Celle-ci met à jour: Le gouvernement (président, ministres), les différents députés et leur président, les différents juges, les différents policiers.\n
209
-
210
- ## Paramètres
211
- institutions: `.State`\n
212
- Le nouvel état des institutions, à sauvegarder.
213
- """
214
-
215
- return # Provisoire
216
-
217
- get_ids = lambda institution : [ member.id for member in institutions.__getattribute__(institution).members ]
218
-
219
- self._put_in_db('functions', { 'id': 'ADMIN', 'users': get_ids('administration') })
220
- self._put_in_db('functions', { 'id': 'REPR', 'users': get_ids('assembly') })
221
- self._put_in_db('functions', { 'id': 'JUDGE', 'users': get_ids('court') })
222
- self._put_in_db('functions', { 'id': 'POLICE', 'users': get_ids('police') })
223
-
224
- self._put_in_db('functions', { 'id': 'PRE_AS', 'users': [ institutions.assembly.president.id ] })
225
- self._put_in_db('functions', { 'id': 'PRE_REP', 'users': [ institutions.government.president.id ] })
226
-
227
- self._put_in_db('functions', { 'id': 'MIN_PRIM', 'users': [ institutions.government.prime_minister.id ] })
228
- self._put_in_db('functions', { 'id': 'MIN_INN', 'users': [ institutions.government.inner_minister.id ] })
229
- self._put_in_db('functions', { 'id': 'MIN_JUS', 'users': [ institutions.government.justice_minister.id ] })
230
- self._put_in_db('functions', { 'id': 'MIN_ECO', 'users': [ institutions.government.economy_minister.id ] })
231
- self._put_in_db('functions', { 'id': 'MIN_AUD', 'users': [ institutions.government.press_minister.id ] })
232
- self._put_in_db('functions', { 'id': 'MIN_OUT', 'users': [ institutions.government.outer_minister.id ] })
233
-
234
- def new_mandate(self, institutions: State, weeks: int = 4):
235
- """
236
- *INDISPONIBLE DANS CETTE VERSION.*\n
237
- Fonction qui amène à supprimer toutes les archives du mandat précédent
238
-
239
- ## Paramètres
240
- - institutions: `.State`\n
241
- Nouvel État à sauvegarder
242
- - weeks: `int`\n
243
- Nombre de semaines du mandat
244
- """
245
-
246
- return # Provisoire
247
-
248
- for item in self.fetch('mandate'):
249
- if item['date'] >= round(time.time()) - weeks * 604800: # On évite de supprimer les informations écrites lors de la période définie
250
- self._delete_by_ID('mandate', item['id'])
251
-
252
- self.update_institutions(institutions)
253
-
254
- """
255
- ---- ARCHIVES ----
256
- """
257
-
258
- def _add_archive(self, archive: Archive):
259
- """
260
- *INDISPONIBLE DANS CETTE VERSION.*\n
261
- Ajoute une archive d'une action (élection, promotion, ou rétrogradation) dans la base de données.
262
-
263
- ## Paramètres
264
- - archive: `.Archive`\n
265
- Archive à ajouter
266
- """
267
-
268
- return # Provisoire
269
-
270
- archive.id = NSID(archive.id)
271
- _data = archive.__dict__.copy()
272
-
273
- if type(archive) == Election:
274
- _data['_type'] = "election"
275
- elif type(archive) == Promotion:
276
- _data['_type'] = "promotion"
277
- elif type(archive) == Demotion:
278
- _data['_type'] = "demotion"
279
- else:
280
- _data['_type'] = "unknown"
281
-
282
- self._put_in_db('archives', _data)
283
- self._put_in_db('mandate', _data) # Ajouter les archives à celle du mandat actuel
284
-
285
- def _get_archive(self, id: NSID) -> Archive | Election | Promotion | Demotion:
286
- """
287
- *INDISPONIBLE DANS CETTE VERSION.*\n
288
- Récupère une archive spécifique.
289
-
290
- ## Paramètres
291
- id: `NSID`\n
292
- ID de l'archive.
293
-
294
- ## Renvoie
295
- - `.Archive | .Election | .Promotion | .Demotion`
296
- """
297
-
298
- return Archive(NSID(id)) # Provisoire
299
-
300
- id = NSID(id)
301
- _data = self._get_by_ID('archives', id)
302
-
303
- if _data is None:
304
- return None
305
-
306
- if _data['_type'] == "election":
307
- archive = Election(_data['author'], _data['target'], _data['details']['position'])
308
- elif _data['_type'] == "promotion":
309
- archive = Promotion(_data['author'], _data['target'], _data['details']['position'])
310
- elif _data['_type'] == "demotion":
311
- archive = Demotion(_data['author'], _data['target'])
312
- else:
313
- archive = Archive(_data['author'], _data['target'])
314
-
315
- archive.id = id
316
- archive.action = _data['action']
317
- archive.date = _data['date']
318
- archive.details = _data['details']
319
-
320
- return archive
321
-
322
- def _fetch_archives(self, **query) -> list[ Archive | Election | Promotion | Demotion ]:
323
- """
324
- *INDISPONIBLE DANS CETTE VERSION.*\n
325
- Récupère une liste d'archives correspondant à la requête.
326
-
327
- ## Paramètres
328
- query: `dict`\n
329
- Requête pour filtrer les archives.
330
-
331
- ## Renvoie
332
- - `list[.Archive | .Election | .Promotion | .Demotion]`
333
- """
334
-
335
- return [] # Provisoire
336
-
337
- _res = self.fetch('archives', **query)
338
-
339
- return [ self._get_archive(archive['id']) for archive in _res ]
@@ -1,15 +0,0 @@
1
- nsarchive/__init__.py,sha256=hYy5bfifzK-HWBv1sfPax4XoPuOpOxUYCcuZc-Lkp_A,656
2
- nsarchive/assets/default_avatar.png,sha256=n-4vG_WPke8LvbY3ZU6oA-H-OtRoIu7woKnRq9DCIlI,51764
3
- nsarchive/cls/archives.py,sha256=3vyGOBZUE-B-G_QMJXRIPD0d-1O5z4wqv-2MRf5AQdA,2506
4
- nsarchive/cls/base.py,sha256=ley35D1i0RTfX_lmPoyC_PICG40UQtLj5zizRWjUwpM,8034
5
- nsarchive/cls/economy.py,sha256=Ap6nhnArieHroHi9zTHUKQgYscLhByNcI74QQ1Fno9c,6992
6
- nsarchive/cls/entities.py,sha256=HcfKydEMqmLkBvoIY2DRGK0PO_6ic5WK826VHaUwyjI,14428
7
- nsarchive/cls/republic.py,sha256=16NFNCkJxOeVRd6BoJ68AlrTESQgRfZ5FSFlNWTEdK0,4103
8
- nsarchive/instances/_economy.py,sha256=vMK8nRBHjLWmAmTu1f3XkWimFUk8tuV3P9KIuKRdNpw,9596
9
- nsarchive/instances/_entities.py,sha256=35S6ZRUUSykoyr4iH1uxn8maBPukGz0vWPyzk6MnSpY,9630
10
- nsarchive/instances/_republic.py,sha256=M8k2rZJvQGzOyZlmqRDiB-d615hZOqD3kuRrgYP4JqA,12004
11
- nsarchive/utils.py,sha256=L37Dm8aO0Sm3FDLPf2tP6fo-1lodDq7JIz-WXttNuJg,684
12
- nsarchive-3.0.0a7.dist-info/LICENSE,sha256=aFLFZg6LEJFpTlNQ8su3__jw4GfV-xWBmC1cePkKZVw,35802
13
- nsarchive-3.0.0a7.dist-info/METADATA,sha256=zSdArlwGKpkpdREPs1eGIbISMuZogrxr69LgUZ392PQ,695
14
- nsarchive-3.0.0a7.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
15
- nsarchive-3.0.0a7.dist-info/RECORD,,