nsarchive 1.3.0__py3-none-any.whl → 2.0.0__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 +20 -806
- nsarchive/cls/archives.py +58 -35
- nsarchive/cls/base.py +174 -14
- nsarchive/cls/economy.py +71 -13
- nsarchive/cls/entities.py +176 -38
- nsarchive/cls/republic.py +104 -20
- nsarchive/instances/_economy.py +313 -0
- nsarchive/instances/_entities.py +321 -0
- nsarchive/instances/_republic.py +313 -0
- nsarchive/utils.py +26 -0
- nsarchive-2.0.0.dist-info/METADATA +20 -0
- nsarchive-2.0.0.dist-info/RECORD +16 -0
- nsarchive/utils/assets.py +0 -15
- nsarchive-1.3.0.dist-info/METADATA +0 -177
- nsarchive-1.3.0.dist-info/RECORD +0 -13
- {nsarchive-1.3.0.dist-info → nsarchive-2.0.0.dist-info}/LICENSE +0 -0
- {nsarchive-1.3.0.dist-info → nsarchive-2.0.0.dist-info}/WHEEL +0 -0
@@ -0,0 +1,313 @@
|
|
1
|
+
import time
|
2
|
+
|
3
|
+
from supabase import create_client
|
4
|
+
|
5
|
+
from ..cls.base import *
|
6
|
+
from ..cls.archives import *
|
7
|
+
from ..cls.republic import *
|
8
|
+
|
9
|
+
from ..cls.exceptions import *
|
10
|
+
|
11
|
+
|
12
|
+
class RepublicInstance(Instance):
|
13
|
+
"""
|
14
|
+
Gère les interactions avec les votes, les archives de la république, et les fonctionnaires.
|
15
|
+
|
16
|
+
## Informations
|
17
|
+
- Résultats des votes et procès: `.Vote | .Referendum | .Lawsuit`
|
18
|
+
- Différentes institutions: `.State | .Administration | .Government | .Assembly | .Court | .PoliceForces`
|
19
|
+
- Occupants des différents rôles et historique de leurs actions: `.Official`
|
20
|
+
"""
|
21
|
+
|
22
|
+
def __init__(self, id: str, token: str) -> None:
|
23
|
+
super().__init__(create_client(f"https://{id}.supabase.co", token))
|
24
|
+
|
25
|
+
"""
|
26
|
+
---- VOTES & REFERENDUMS ----
|
27
|
+
"""
|
28
|
+
|
29
|
+
def get_vote(self, id: NSID) -> Vote | Referendum | Lawsuit:
|
30
|
+
"""
|
31
|
+
Récupère un vote spécifique.
|
32
|
+
|
33
|
+
## Paramètres
|
34
|
+
id: `NSID`\n
|
35
|
+
ID du vote.
|
36
|
+
|
37
|
+
## Renvoie
|
38
|
+
- `.Vote | .Referendum | .Lawsuit`
|
39
|
+
"""
|
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
|
+
Sauvegarde un vote dans la base de données.
|
78
|
+
|
79
|
+
## Paramètres
|
80
|
+
- vote: `.Vote`\n
|
81
|
+
Vote à sauvegarder
|
82
|
+
"""
|
83
|
+
|
84
|
+
vote.id = NSID(vote.id)
|
85
|
+
|
86
|
+
_data = {
|
87
|
+
'_type':'vote' if type(vote) == Vote else\
|
88
|
+
'referendum' if type(vote) == Referendum else\
|
89
|
+
'lawsuit' if type(vote) == Lawsuit else\
|
90
|
+
'unknown',
|
91
|
+
'id': NSID(vote.id),
|
92
|
+
'title': vote.title,
|
93
|
+
'author_id': NSID(vote.author),
|
94
|
+
'start_date': vote.startDate,
|
95
|
+
'end_date': vote.endDate,
|
96
|
+
'choices': [ opt.__dict__ for opt in vote.choices ]
|
97
|
+
}
|
98
|
+
|
99
|
+
if type(vote) == Lawsuit:
|
100
|
+
del _data['_type']
|
101
|
+
self._put_in_db('lawsuits', _data)
|
102
|
+
else:
|
103
|
+
self._put_in_db('votes', _data)
|
104
|
+
|
105
|
+
# Aucune possibilité de supprimer un vote
|
106
|
+
|
107
|
+
"""
|
108
|
+
---- INSTITUTION & MANDAT ----
|
109
|
+
"""
|
110
|
+
|
111
|
+
def get_official(self, id: NSID, current_mandate: bool = True) -> Official:
|
112
|
+
"""
|
113
|
+
Récupère les informations d'un fonctionnaire (mandats, contributions).
|
114
|
+
|
115
|
+
## Paramètres
|
116
|
+
id: `NSID`\n
|
117
|
+
ID du fonctionnaire.
|
118
|
+
current_mandate: `bool`\n
|
119
|
+
Indique si l'on doit récupérer le mandat actuel ou les anciens mandats.
|
120
|
+
|
121
|
+
## Renvoie
|
122
|
+
- `.Official`
|
123
|
+
"""
|
124
|
+
|
125
|
+
id = NSID(id)
|
126
|
+
|
127
|
+
base = 'mandate' if current_mandate else 'archives'
|
128
|
+
|
129
|
+
_contributions = self.fetch(base, author = id, _type = 'contrib')
|
130
|
+
_mandates = self.fetch(base, target = id, _type = 'election') +\
|
131
|
+
self.fetch(base, target = id, _type = 'promotion')
|
132
|
+
|
133
|
+
user = Official(id)
|
134
|
+
for mandate in _mandates:
|
135
|
+
if mandate['details']['position'].startswith('MIN'):
|
136
|
+
mandate['details']['position'] = 'MIN'
|
137
|
+
|
138
|
+
try:
|
139
|
+
user.mandates[mandate['details']['position']] += 1
|
140
|
+
except KeyError:
|
141
|
+
user.mandates[mandate['details']['position']] = 1
|
142
|
+
|
143
|
+
for contrib in _contributions:
|
144
|
+
try:
|
145
|
+
user.contributions[contrib['action']] += 1
|
146
|
+
except KeyError:
|
147
|
+
user.contributions[contrib['action']] = 1
|
148
|
+
|
149
|
+
return user
|
150
|
+
|
151
|
+
def get_institutions(self) -> State:
|
152
|
+
"""Récupère l'état actuel des institutions de la république."""
|
153
|
+
|
154
|
+
admin = Administration()
|
155
|
+
gov = Government(Official('0'))
|
156
|
+
assembly = Assembly()
|
157
|
+
court = Court()
|
158
|
+
police_forces = PoliceForces()
|
159
|
+
|
160
|
+
_get_position: list[dict] = lambda pos : self._select_from_db('functions', 'id', pos)[0]['users']
|
161
|
+
|
162
|
+
admin.members = [ self.get_official(user) for user in _get_position('ADMIN') ]
|
163
|
+
admin.president = self.get_official(0xF7DB60DD1C4300A) # happex (remplace Kheops pour l'instant)
|
164
|
+
|
165
|
+
gov.president = self.get_official(0x0)
|
166
|
+
|
167
|
+
minister = lambda code : self.get_official(_get_position(f'MIN_{code}')[0])
|
168
|
+
gov.prime_minister = minister('PRIM')
|
169
|
+
gov.economy_minister = minister('ECO')
|
170
|
+
gov.inner_minister = minister('INN')
|
171
|
+
gov.press_minister = minister('AUD')
|
172
|
+
gov.justice_minister = minister('JUS')
|
173
|
+
gov.outer_minister = minister('OUT')
|
174
|
+
|
175
|
+
assembly.president = self.get_official(_get_position('PRE_AS')[0])
|
176
|
+
assembly.members = [ self.get_official(user) for user in _get_position('REPR') ]
|
177
|
+
|
178
|
+
court.president = gov.justice_minister
|
179
|
+
court.members = [ self.get_official(user) for user in _get_position('JUDGE') ]
|
180
|
+
|
181
|
+
police_forces.president = gov.inner_minister
|
182
|
+
police_forces.members = [ self.get_official(user) for user in _get_position('POLICE') ]
|
183
|
+
|
184
|
+
instits = State()
|
185
|
+
instits.administration = admin
|
186
|
+
instits.government = gov
|
187
|
+
instits.court = court
|
188
|
+
instits.assembly = assembly
|
189
|
+
instits.police = police_forces
|
190
|
+
|
191
|
+
return instits
|
192
|
+
|
193
|
+
def update_institutions(self, institutions: State):
|
194
|
+
"""
|
195
|
+
Fonction communément appelée après un vote législatif ou une nomination.\n
|
196
|
+
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
|
197
|
+
|
198
|
+
## Paramètres
|
199
|
+
institutions: `.State`\n
|
200
|
+
Le nouvel état des institutions, à sauvegarder.
|
201
|
+
"""
|
202
|
+
|
203
|
+
get_ids = lambda institution : [ member.id for member in institutions.__getattribute__(institution).members ]
|
204
|
+
|
205
|
+
self._put_in_db('functions', { 'id': 'ADMIN', 'users': get_ids('administration') })
|
206
|
+
self._put_in_db('functions', { 'id': 'REPR', 'users': get_ids('assembly') })
|
207
|
+
self._put_in_db('functions', { 'id': 'JUDGE', 'users': get_ids('court') })
|
208
|
+
self._put_in_db('functions', { 'id': 'POLICE', 'users': get_ids('police') })
|
209
|
+
|
210
|
+
self._put_in_db('functions', { 'id': 'PRE_AS', 'users': [ institutions.assembly.president.id ] })
|
211
|
+
self._put_in_db('functions', { 'id': 'PRE_REP', 'users': [ institutions.government.president.id ] })
|
212
|
+
|
213
|
+
self._put_in_db('functions', { 'id': 'MIN_PRIM', 'users': [ institutions.government.prime_minister.id ] })
|
214
|
+
self._put_in_db('functions', { 'id': 'MIN_INN', 'users': [ institutions.government.inner_minister.id ] })
|
215
|
+
self._put_in_db('functions', { 'id': 'MIN_JUS', 'users': [ institutions.government.justice_minister.id ] })
|
216
|
+
self._put_in_db('functions', { 'id': 'MIN_ECO', 'users': [ institutions.government.economy_minister.id ] })
|
217
|
+
self._put_in_db('functions', { 'id': 'MIN_AUD', 'users': [ institutions.government.press_minister.id ] })
|
218
|
+
self._put_in_db('functions', { 'id': 'MIN_OUT', 'users': [ institutions.government.outer_minister.id ] })
|
219
|
+
|
220
|
+
def new_mandate(self, institutions: State, weeks: int = 4):
|
221
|
+
"""
|
222
|
+
Fonction qui amène à supprimer toutes les archives du mandat précédent
|
223
|
+
|
224
|
+
## Paramètres
|
225
|
+
- institutions: `.State`\n
|
226
|
+
Nouvel État à sauvegarder
|
227
|
+
- weeks: `int`\n
|
228
|
+
Nombre de semaines du mandat
|
229
|
+
"""
|
230
|
+
|
231
|
+
for item in self.fetch('mandate'):
|
232
|
+
if item['date'] >= round(time.time()) - weeks * 604800: # On évite de supprimer les informations écrites lors de la période définie
|
233
|
+
self._delete_by_ID('mandate', item['id'])
|
234
|
+
|
235
|
+
self.update_institutions(institutions)
|
236
|
+
|
237
|
+
"""
|
238
|
+
---- ARCHIVES ----
|
239
|
+
"""
|
240
|
+
|
241
|
+
def _add_archive(self, archive: Archive):
|
242
|
+
"""
|
243
|
+
Ajoute une archive d'une action (élection, promotion, ou rétrogradation) dans la base de données.
|
244
|
+
|
245
|
+
## Paramètres
|
246
|
+
- archive: `.Archive`\n
|
247
|
+
Archive à ajouter
|
248
|
+
"""
|
249
|
+
|
250
|
+
archive.id = NSID(archive.id)
|
251
|
+
_data = archive.__dict__.copy()
|
252
|
+
|
253
|
+
if type(archive) == Election:
|
254
|
+
_data['_type'] = "election"
|
255
|
+
elif type(archive) == Promotion:
|
256
|
+
_data['_type'] = "promotion"
|
257
|
+
elif type(archive) == Demotion:
|
258
|
+
_data['_type'] = "demotion"
|
259
|
+
else:
|
260
|
+
_data['_type'] = "unknown"
|
261
|
+
|
262
|
+
self._put_in_db('archives', _data)
|
263
|
+
self._put_in_db('mandate', _data) # Ajouter les archives à celle du mandat actuel
|
264
|
+
|
265
|
+
def _get_archive(self, id: NSID) -> Archive | Election | Promotion | Demotion:
|
266
|
+
"""
|
267
|
+
Récupère une archive spécifique.
|
268
|
+
|
269
|
+
## Paramètres
|
270
|
+
id: `NSID`\n
|
271
|
+
ID de l'archive.
|
272
|
+
|
273
|
+
## Renvoie
|
274
|
+
- `.Archive | .Election | .Promotion | .Demotion`
|
275
|
+
"""
|
276
|
+
|
277
|
+
id = NSID(id)
|
278
|
+
_data = self._get_by_ID('archives', id)
|
279
|
+
|
280
|
+
if _data is None:
|
281
|
+
return None
|
282
|
+
|
283
|
+
if _data['_type'] == "election":
|
284
|
+
archive = Election(_data['author'], _data['target'], _data['details']['position'])
|
285
|
+
elif _data['_type'] == "promotion":
|
286
|
+
archive = Promotion(_data['author'], _data['target'], _data['details']['position'])
|
287
|
+
elif _data['_type'] == "demotion":
|
288
|
+
archive = Demotion(_data['author'], _data['target'])
|
289
|
+
else:
|
290
|
+
archive = Archive(_data['author'], _data['target'])
|
291
|
+
|
292
|
+
archive.id = id
|
293
|
+
archive.action = _data['action']
|
294
|
+
archive.date = _data['date']
|
295
|
+
archive.details = _data['details']
|
296
|
+
|
297
|
+
return archive
|
298
|
+
|
299
|
+
def _fetch_archives(self, **query) -> list[ Archive | Election | Promotion | Demotion ]:
|
300
|
+
"""
|
301
|
+
Récupère une liste d'archives correspondant à la requête.
|
302
|
+
|
303
|
+
## Paramètres
|
304
|
+
query: `dict`\n
|
305
|
+
Requête pour filtrer les archives.
|
306
|
+
|
307
|
+
## Renvoie
|
308
|
+
- `list[.Archive | .Election | .Promotion | .Demotion]`
|
309
|
+
"""
|
310
|
+
|
311
|
+
_res = self.fetch('archives', **query)
|
312
|
+
|
313
|
+
return [ self._get_archive(archive['id']) for archive in _res ]
|
nsarchive/utils.py
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
import io
|
2
|
+
import math
|
3
|
+
import os
|
4
|
+
from PIL import Image
|
5
|
+
|
6
|
+
def open_asset(path: str) -> bytes:
|
7
|
+
curr_dir = os.path.dirname(os.path.abspath(os.path.join(__file__)))
|
8
|
+
asset_path = os.path.join(curr_dir, 'assets', path)
|
9
|
+
|
10
|
+
image = Image.open(asset_path)
|
11
|
+
val = io.BytesIO()
|
12
|
+
|
13
|
+
image.save(val, format = 'PNG')
|
14
|
+
|
15
|
+
return val.getvalue()
|
16
|
+
|
17
|
+
def compress_image(data: bytes, _max: int = 1000 ** 2) -> bytes:
|
18
|
+
img = Image.open(io.BytesIO(data))
|
19
|
+
size = 2 * ( math.floor(math.sqrt(_max),) )
|
20
|
+
|
21
|
+
img.resize(size)
|
22
|
+
|
23
|
+
val = io.BytesIO()
|
24
|
+
img.save(val)
|
25
|
+
|
26
|
+
return val.getvalue()
|
@@ -0,0 +1,20 @@
|
|
1
|
+
Metadata-Version: 2.1
|
2
|
+
Name: nsarchive
|
3
|
+
Version: 2.0.0
|
4
|
+
Summary: API-wrapper pour récupérer des données liées à Nation
|
5
|
+
License: GPL-3.0
|
6
|
+
Author: happex
|
7
|
+
Author-email: 110610727+okayhappex@users.noreply.github.com
|
8
|
+
Requires-Python: >=3.10,<4.0
|
9
|
+
Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3)
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
11
|
+
Classifier: Programming Language :: Python :: 3.10
|
12
|
+
Classifier: Programming Language :: Python :: 3.11
|
13
|
+
Classifier: Programming Language :: Python :: 3.12
|
14
|
+
Requires-Dist: pillow (>=10.4,<11.0)
|
15
|
+
Requires-Dist: supabase (>=2.9.1,<3.0.0)
|
16
|
+
Description-Content-Type: text/markdown
|
17
|
+
|
18
|
+
# NSArchive
|
19
|
+
|
20
|
+
Documentation pas disponible pour l'instant
|
@@ -0,0 +1,16 @@
|
|
1
|
+
nsarchive/__init__.py,sha256=_hwIocDyD7R-4rS7ypca8jZex93H6mK-b9NpTpt-Rvo,724
|
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=7gbXtKZaqkr8NWf-0oZaZ0alR9JSx_G1Qf7Sbn-MbF0,5611
|
5
|
+
nsarchive/cls/economy.py,sha256=soe3ATrtQem-u80vz8nXfsn_3TqMdhpolyTxRenH2C0,2742
|
6
|
+
nsarchive/cls/entities.py,sha256=fAxn4V64dqoB1wq7t-kByARlrr_jKzPzqpvFO_ECXnI,10144
|
7
|
+
nsarchive/cls/exceptions.py,sha256=QN6Qn7cxTkGoC4lO50hBAq4gZCgo7scQvCkb-xKl6Xs,692
|
8
|
+
nsarchive/cls/republic.py,sha256=16NFNCkJxOeVRd6BoJ68AlrTESQgRfZ5FSFlNWTEdK0,4103
|
9
|
+
nsarchive/instances/_economy.py,sha256=trReX8u5QrgcYm6RElV-gNjVyFbZWO783XTDMm9JJj4,7777
|
10
|
+
nsarchive/instances/_entities.py,sha256=AmpnXz1penQz09bhnErK8QKU6WnVwGwc3txkHc-OFfY,10635
|
11
|
+
nsarchive/instances/_republic.py,sha256=5cOihYch6n2dyYAqiNYMdwerwcyZ9Y80f5cRtvkiH-o,11289
|
12
|
+
nsarchive/utils.py,sha256=qpQCZLlbVApOLtCI2ml54QwUld6K8fDxyBfwzofqXzw,610
|
13
|
+
nsarchive-2.0.0.dist-info/LICENSE,sha256=aFLFZg6LEJFpTlNQ8su3__jw4GfV-xWBmC1cePkKZVw,35802
|
14
|
+
nsarchive-2.0.0.dist-info/METADATA,sha256=MYuiI2Ga-zKQPWApI69ORP0JiXYDoWyRNu9utwP1Q8s,696
|
15
|
+
nsarchive-2.0.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
16
|
+
nsarchive-2.0.0.dist-info/RECORD,,
|
nsarchive/utils/assets.py
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
import io
|
2
|
-
import os
|
3
|
-
from PIL import Image
|
4
|
-
|
5
|
-
def open(path: str) -> Image:
|
6
|
-
curr_dir = os.path.dirname(os.path.abspath(os.path.join(__file__)))
|
7
|
-
parent_dir = os.path.dirname(curr_dir)
|
8
|
-
asset_path = os.path.join(parent_dir, 'assets', path)
|
9
|
-
|
10
|
-
image = Image.open(asset_path)
|
11
|
-
val = io.BytesIO()
|
12
|
-
|
13
|
-
image.save(val, format = 'PNG')
|
14
|
-
|
15
|
-
return val.getvalue()
|
@@ -1,177 +0,0 @@
|
|
1
|
-
Metadata-Version: 2.1
|
2
|
-
Name: nsarchive
|
3
|
-
Version: 1.3.0
|
4
|
-
Summary:
|
5
|
-
License: GPL-3.0
|
6
|
-
Author: happex
|
7
|
-
Author-email: 110610727+okayhappex@users.noreply.github.com
|
8
|
-
Requires-Python: >=3.10,<4.0
|
9
|
-
Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3)
|
10
|
-
Classifier: Programming Language :: Python :: 3
|
11
|
-
Classifier: Programming Language :: Python :: 3.10
|
12
|
-
Classifier: Programming Language :: Python :: 3.11
|
13
|
-
Classifier: Programming Language :: Python :: 3.12
|
14
|
-
Requires-Dist: deta (>=1.2,<2.0)
|
15
|
-
Requires-Dist: pillow (>=10.4,<11.0)
|
16
|
-
Description-Content-Type: text/markdown
|
17
|
-
|
18
|
-
# nsarchive
|
19
|
-
|
20
|
-
`nsarchive` est un module Python pour la gestion des entités (utilisateurs et organisations) à l'aide de la base de données Deta. Ce module permet de créer, récupérer, sauvegarder et gérer des entités et leurs attributs spécifiques.
|
21
|
-
|
22
|
-
## Pré-requis
|
23
|
-
|
24
|
-
Listes des choses à avoir afin de pouvoir utiliser le module correctement:
|
25
|
-
- [Python 3.10](https://www.python.org/downloads/) ou supérieur
|
26
|
-
- Un token [Deta](https://deta.space), donné par un administrateur ou pour votre collection personnelle
|
27
|
-
- Un bon capuccino, pour commencer la programmation en bons termes
|
28
|
-
|
29
|
-
> **Note:** Il vous faudra un token différent pour accéder aux différentes parties de la base de données. Vos tokens n'expireront pas à moins que l'ordre en aura été donné
|
30
|
-
|
31
|
-
## Installation
|
32
|
-
|
33
|
-
Vous pouvez installer ce module via pip :
|
34
|
-
|
35
|
-
```sh
|
36
|
-
pip install nsarchive
|
37
|
-
```
|
38
|
-
|
39
|
-
## Utilisation
|
40
|
-
|
41
|
-
### Importation et Initialisation
|
42
|
-
|
43
|
-
Pour utiliser `nsarchive`, commencez par importer le module et initialiser une instance d'`EntityInstance` avec votre token Deta.
|
44
|
-
|
45
|
-
```python
|
46
|
-
from nsarchive import EntityInstance
|
47
|
-
|
48
|
-
# Remplacez 'your_deta_token' par votre véritable token Deta
|
49
|
-
entity_instance = EntityInstance(token = 'your_deta_token')
|
50
|
-
```
|
51
|
-
|
52
|
-
### Récupérer une Entité
|
53
|
-
|
54
|
-
Vous pouvez récupérer une entité (Utilisateur ou Organisation) à l'aide de son ID.
|
55
|
-
|
56
|
-
```python
|
57
|
-
entity = entity_instance.get_entity(id = 'entity_id')
|
58
|
-
print(entity.name)
|
59
|
-
```
|
60
|
-
|
61
|
-
**ATTENTION: Les entités sont identifiées sous une forme hexadécimale. Pour les avoir, vous devez convertir leur ID Discord en hexadécimale puis enlever le préfixe `0x`.**
|
62
|
-
|
63
|
-
Pour les organisations, l'ID Discord correspondra à la formule suivante: `ID fondateur // 100000`.
|
64
|
-
|
65
|
-
N'oubliez pas de toujours utiliser un `str` dans les ID pour interagir avec la base de données.
|
66
|
-
|
67
|
-
### Sauvegarder une Entité
|
68
|
-
|
69
|
-
Après avoir modifié une entité, vous pouvez la sauvegarder dans la base de données.
|
70
|
-
|
71
|
-
```python
|
72
|
-
entity.rename("Nouveau Nom")
|
73
|
-
entity_instance.save_entity(entity)
|
74
|
-
```
|
75
|
-
|
76
|
-
### Rechercher des Entités
|
77
|
-
|
78
|
-
Vous pouvez rechercher des entités avec des critères spécifiques.
|
79
|
-
|
80
|
-
```python
|
81
|
-
entities = entity_instance.fetch_entity(query = {'name': 'Alice'})
|
82
|
-
for entity in entities:
|
83
|
-
print(entity['name'])
|
84
|
-
```
|
85
|
-
|
86
|
-
### Gérer les Organisations
|
87
|
-
|
88
|
-
Les organisations peuvent avoir des membres et des certifications. Voici comment ajouter un membre ou une certification.
|
89
|
-
|
90
|
-
```python
|
91
|
-
organization = entity_instance.get_entity(id = 'org_id')
|
92
|
-
user = entity_instance.get_entity(id = 'user_id')
|
93
|
-
|
94
|
-
# Ajouter un membre
|
95
|
-
organization.add_member(user)
|
96
|
-
entity_instance.save_entity(organization)
|
97
|
-
|
98
|
-
# Ajouter une certification
|
99
|
-
organization.add_certification('Certification Example')
|
100
|
-
entity_instance.save_entity(organization)
|
101
|
-
```
|
102
|
-
|
103
|
-
Les certifications pourront être utilisées pour vérifier l'officialité d'une organisation, mais également pour déterminer si l'on peut accorder (ou non) des permissions à ses membres.
|
104
|
-
|
105
|
-
### Exemples de Classes
|
106
|
-
|
107
|
-
#### `Entity`
|
108
|
-
|
109
|
-
Classe parente des classes `User` et `Organization`, elle est utilisée lorsque le module ne peut pas déterminer l'appartenance d'une identité à l'une de ces deux classes ou à l'autre.
|
110
|
-
|
111
|
-
```python
|
112
|
-
from nsarchive.cls.entities import Entity
|
113
|
-
|
114
|
-
entity = Entity(id='entity_id')
|
115
|
-
entity.rename('New Name')
|
116
|
-
entity.add_xp(100)
|
117
|
-
print(entity.get_level())
|
118
|
-
```
|
119
|
-
|
120
|
-
#### `User`
|
121
|
-
|
122
|
-
```python
|
123
|
-
from nsarchive.cls.entities import User
|
124
|
-
|
125
|
-
user = User(id = 'user_id')
|
126
|
-
user.edit_boost(name = 'admin', multiplier = 5) # Négliger le paramètre <multiplier> ou le fixer à un nombre négatif reviendrait à supprimer le boost.
|
127
|
-
print(user.boosts)
|
128
|
-
```
|
129
|
-
|
130
|
-
> **Note:** Lorsqu'on ajoute de l'expérience à un utilisateur via la méthode `add_xp`, le nombre de points ajoutés est automatiquement multiplié par le bonus le plus important dont l'utilisateur bénéficie.
|
131
|
-
|
132
|
-
#### `Organization`
|
133
|
-
|
134
|
-
```python
|
135
|
-
from nsarchive.cls.entities import Organization
|
136
|
-
|
137
|
-
organization = Organization(id = 'org_id')
|
138
|
-
organization.set_owner(user)
|
139
|
-
organization.add_member(user)
|
140
|
-
print(organization.members)
|
141
|
-
```
|
142
|
-
|
143
|
-
> **Note:** Les attributs `owner` et `members` sont indépendants. L'owner peut être n'importe quelle personne faisant ou non partie des `members`.
|
144
|
-
|
145
|
-
## Gestion des Exceptions
|
146
|
-
|
147
|
-
`nsarchive` fournit des exceptions spécifiques pour gérer les erreurs courantes.
|
148
|
-
|
149
|
-
#### `NameTooLongError`
|
150
|
-
|
151
|
-
Lancé lorsque le nom d'une entité dépasse la longueur maximale autorisée (32 caractères).
|
152
|
-
|
153
|
-
```python
|
154
|
-
from nsarchive.cls.exceptions import NameTooLongError
|
155
|
-
|
156
|
-
try:
|
157
|
-
entity.rename('Ce nom est long, voire même très long, je dirais même extrêmement long')
|
158
|
-
except NameTooLongError as e:
|
159
|
-
print(e)
|
160
|
-
```
|
161
|
-
|
162
|
-
#### `EntityTypeError`
|
163
|
-
|
164
|
-
Lancé lorsque le type d'entité est incorrect. Vous ne devriez normalement pas la rencontrer en utilisant le module, mais elle pourrait vous être utile.
|
165
|
-
|
166
|
-
```python
|
167
|
-
from nsarchive.cls.exceptions import EntityTypeError
|
168
|
-
|
169
|
-
try:
|
170
|
-
# Code qui peut lancer une EntityTypeError
|
171
|
-
except EntityTypeError as e:
|
172
|
-
print(e)
|
173
|
-
```
|
174
|
-
|
175
|
-
## License
|
176
|
-
|
177
|
-
Ce projet est sous licence GNU GPL-3.0 - Voir le fichier [LICENSE](LICENSE) pour plus de détails.
|
nsarchive-1.3.0.dist-info/RECORD
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
nsarchive/__init__.py,sha256=idTG-9WiUJZ6rkkRXwjBvt_lC-lOKyz6eSS22vSMi3k,27011
|
2
|
-
nsarchive/assets/default_avatar.png,sha256=n-4vG_WPke8LvbY3ZU6oA-H-OtRoIu7woKnRq9DCIlI,51764
|
3
|
-
nsarchive/cls/archives.py,sha256=i4R7NPYXX_1oi0oLAvL_4SqyjqPutXSXKysUetE6hME,2001
|
4
|
-
nsarchive/cls/base.py,sha256=DGDm0uD96M00-qvdKsltU9kAfAOBr85Ov0b18gTnoIM,714
|
5
|
-
nsarchive/cls/economy.py,sha256=JpNB06JHek4uUapdk89-SR3DEoSyxXPn8OqZJkOZH_E,1252
|
6
|
-
nsarchive/cls/entities.py,sha256=Rvu2Q1mTWqQ-z92j-OXhoXSWked7p4tOCJm0gIlnP9c,6179
|
7
|
-
nsarchive/cls/exceptions.py,sha256=QN6Qn7cxTkGoC4lO50hBAq4gZCgo7scQvCkb-xKl6Xs,692
|
8
|
-
nsarchive/cls/republic.py,sha256=6eut6OsFoOm9TVhA41fM3NlMEA3Uhg9TCuXgl46vFko,1985
|
9
|
-
nsarchive/utils/assets.py,sha256=hd0STSpa0yT-OJlUyI_wCYXJqcBiUMQds2pZTXNNg9c,382
|
10
|
-
nsarchive-1.3.0.dist-info/LICENSE,sha256=aFLFZg6LEJFpTlNQ8su3__jw4GfV-xWBmC1cePkKZVw,35802
|
11
|
-
nsarchive-1.3.0.dist-info/METADATA,sha256=kndn-qxF_P0cYEo92vaKArA1Vpgn35ao_y7poWqQFo8,5629
|
12
|
-
nsarchive-1.3.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
13
|
-
nsarchive-1.3.0.dist-info/RECORD,,
|
File without changes
|
File without changes
|