nsarchive 1.4.0__py3-none-any.whl → 2.0.0a1__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 -820
- nsarchive/cls/base.py +110 -14
- nsarchive/cls/economy.py +3 -4
- nsarchive/cls/entities.py +27 -25
- nsarchive/cls/republic.py +25 -8
- nsarchive/instances/_economy.py +251 -0
- nsarchive/instances/_entities.py +311 -0
- nsarchive/instances/_republic.py +282 -0
- nsarchive/utils/assets.py +1 -1
- {nsarchive-1.4.0.dist-info → nsarchive-2.0.0a1.dist-info}/METADATA +3 -3
- nsarchive-2.0.0a1.dist-info/RECORD +16 -0
- nsarchive-1.4.0.dist-info/RECORD +0 -13
- {nsarchive-1.4.0.dist-info → nsarchive-2.0.0a1.dist-info}/LICENSE +0 -0
- {nsarchive-1.4.0.dist-info → nsarchive-2.0.0a1.dist-info}/WHEEL +0 -0
@@ -0,0 +1,311 @@
|
|
1
|
+
from supabase import create_client
|
2
|
+
|
3
|
+
from ..cls.base import *
|
4
|
+
from ..cls.entities import *
|
5
|
+
from ..cls.archives import *
|
6
|
+
|
7
|
+
from ..cls.exceptions import *
|
8
|
+
|
9
|
+
class EntityInstance(Instance):
|
10
|
+
"""
|
11
|
+
Instance qui vous permettra d'interagir avec les profils des membres ainsi que les différents métiers et secteurs d'activité.
|
12
|
+
|
13
|
+
## Informations disponibles
|
14
|
+
- Profil des membres et des entreprises: `.User | .Organization | .Entity`
|
15
|
+
- Participation d'un membre à différent votes: `.User | .Organization | .Entity`
|
16
|
+
- Appartenance et permissions d'un membre dans un groupe: `.GroupMember.MemberPermissions`
|
17
|
+
- Position légale et permissions d'une entité: `.Position.Permissions`
|
18
|
+
- Sanctions et modifications d'une entité: `.Action[ .AdminAction | .Sanction ]`
|
19
|
+
"""
|
20
|
+
|
21
|
+
def __init__(self, id: str, token: str) -> None:
|
22
|
+
super().__init__(create_client(f"https://{id}.supabase.co", token))
|
23
|
+
|
24
|
+
"""
|
25
|
+
---- ENTITÉS ----
|
26
|
+
"""
|
27
|
+
|
28
|
+
def get_entity(self, id: str | NSID) -> User | Organization | Entity:
|
29
|
+
"""
|
30
|
+
Fonction permettant de récupérer le profil public d'une entité.\n
|
31
|
+
|
32
|
+
## Paramètres
|
33
|
+
id: `NSID`\n
|
34
|
+
ID héxadécimal de l'entité à récupérer
|
35
|
+
|
36
|
+
## Renvoie
|
37
|
+
- `.User` dans le cas où l'entité choisie est un membre
|
38
|
+
- `.Organization` dans le cas où c'est un groupe
|
39
|
+
- `.Entity` dans le cas où c'est indéterminé
|
40
|
+
"""
|
41
|
+
|
42
|
+
id = NSID(id)
|
43
|
+
|
44
|
+
_data = self._get_by_ID('individuals', id)
|
45
|
+
|
46
|
+
if _data is None: # Aucune entité individuelle sous cet ID
|
47
|
+
_data = self._get_by_ID('organizations', id) # On cherche du côté des groupes
|
48
|
+
else:
|
49
|
+
_data['_type'] = 'user'
|
50
|
+
|
51
|
+
if _data is None: # ID inexistant chez les entités
|
52
|
+
return None
|
53
|
+
elif '_type' not in _data.keys(): # S'il existe chez les organisations, clé '_type' pas encore initialisée
|
54
|
+
_data['_type'] = 'organization'
|
55
|
+
|
56
|
+
if _data['_type'] == 'user':
|
57
|
+
entity = User(id)
|
58
|
+
|
59
|
+
entity.xp = _data['xp']
|
60
|
+
entity.boosts = _data['boosts']
|
61
|
+
|
62
|
+
entity.votes = [ NSID(vote) for vote in _data['votes'] ]
|
63
|
+
elif _data['_type'] == 'organization':
|
64
|
+
entity = Organization(id)
|
65
|
+
|
66
|
+
entity.owner = self.get_entity(NSID(_data['owner_id']))
|
67
|
+
|
68
|
+
for _member in _data['members']:
|
69
|
+
member = GroupMember(_member['id'])
|
70
|
+
member.permission_level = _member['level']
|
71
|
+
|
72
|
+
_member_profile = self.get_entity(member.id)
|
73
|
+
|
74
|
+
member.set_name(_member_profile.name)
|
75
|
+
member.legalPosition = _member_profile.legalPosition
|
76
|
+
member.registerDate = _member_profile.registerDate
|
77
|
+
|
78
|
+
member.xp = _member_profile.xp
|
79
|
+
member.boosts = _member_profile.boosts
|
80
|
+
|
81
|
+
member.permissions = _member_profile.permissions
|
82
|
+
member.votes = _member_profile.votes
|
83
|
+
|
84
|
+
entity.append(member)
|
85
|
+
|
86
|
+
entity.certifications = _data['certifications']
|
87
|
+
entity.shares = _data['shares']
|
88
|
+
else:
|
89
|
+
entity = Entity(id)
|
90
|
+
|
91
|
+
entity.name = _data['name']
|
92
|
+
entity.legalPosition = _data['position'] # Métier si c'est un utilisateur, domaine professionnel si c'est un collectif
|
93
|
+
entity.registerDate = _data['register_date']
|
94
|
+
|
95
|
+
for key, value in _data.get('additional', {}).items():
|
96
|
+
if isinstance(value, str) and value.startswith('\n'):
|
97
|
+
entity.add_link(key, int(value[1:]))
|
98
|
+
else:
|
99
|
+
entity.add_link(key, value)
|
100
|
+
|
101
|
+
return entity
|
102
|
+
|
103
|
+
def save_entity(self, entity: Entity) -> None:
|
104
|
+
"""
|
105
|
+
Fonction permettant de créer ou modifier une entité.
|
106
|
+
|
107
|
+
## Paramètres
|
108
|
+
entity: `.Entity` ( `.User | .Organization` )
|
109
|
+
L'entité à sauvegarder
|
110
|
+
"""
|
111
|
+
|
112
|
+
entity.id = NSID(entity.id)
|
113
|
+
|
114
|
+
_data = {
|
115
|
+
'id': entity.id,
|
116
|
+
'name': entity.name,
|
117
|
+
'position': entity.legalPosition,
|
118
|
+
'register_date': entity.registerDate,
|
119
|
+
'additional': {},
|
120
|
+
}
|
121
|
+
|
122
|
+
for key, value in entity.additional.items():
|
123
|
+
if isinstance(value, int) and len(str(int)) >= 15:
|
124
|
+
_data['additional'][key] = '\n' + str(value)
|
125
|
+
elif type(value) in (str, int):
|
126
|
+
_data['additional'][key] = value
|
127
|
+
|
128
|
+
if type(entity) == Organization:
|
129
|
+
_data['owner_id'] = NSID(entity.owner.id) if entity.owner else NSID("0")
|
130
|
+
_data['members'] = []
|
131
|
+
_data['certifications'] = entity.certifications
|
132
|
+
|
133
|
+
for member in entity.members:
|
134
|
+
_member = {
|
135
|
+
'id': NSID(member.id),
|
136
|
+
'position': member.permission_level
|
137
|
+
}
|
138
|
+
|
139
|
+
_data['members'] += [_member]
|
140
|
+
elif type(entity) == User:
|
141
|
+
_data['xp'] = entity.xp
|
142
|
+
_data['boosts'] = entity.boosts
|
143
|
+
_data['votes'] = [ NSID(vote) for vote in entity.votes]
|
144
|
+
|
145
|
+
self._put_in_db('individuals' if isinstance(entity, User) else 'organizations', _data)
|
146
|
+
|
147
|
+
def delete_entity(self, entity: Entity) -> None:
|
148
|
+
"""
|
149
|
+
Fonction permettant de supprimer le profil d'une entité
|
150
|
+
|
151
|
+
## Paramètres
|
152
|
+
entity: `.Entity` ( `.User | .Organization` )
|
153
|
+
L'entité à supprimer
|
154
|
+
"""
|
155
|
+
|
156
|
+
self._delete_by_ID('individuals' if isinstance(entity, User) else 'organizations', NSID(entity.id))
|
157
|
+
|
158
|
+
def fetch_entities(self, query: dict = None) -> list[ Entity | User | Organization ]:
|
159
|
+
"""
|
160
|
+
Récupère une liste d'entités en fonction d'une requête.
|
161
|
+
|
162
|
+
## Paramètres
|
163
|
+
query: `dict`
|
164
|
+
La requête pour filtrer les entités.
|
165
|
+
|
166
|
+
## Renvoie
|
167
|
+
- `list[Entity | User | Organization]`
|
168
|
+
"""
|
169
|
+
|
170
|
+
_res = self.fetch('entities', **query)
|
171
|
+
|
172
|
+
return [ self.get_entity(NSID(entity['key'])) for entity in _res if entity is not None ]
|
173
|
+
|
174
|
+
def get_entity_groups(self, id: str | NSID) -> list[Organization]:
|
175
|
+
"""
|
176
|
+
Récupère les groupes auxquels appartient une entité.
|
177
|
+
|
178
|
+
## Paramètres
|
179
|
+
id: `str | NSID`
|
180
|
+
ID de l'entité.
|
181
|
+
|
182
|
+
## Renvoie
|
183
|
+
- `list[Organization]`
|
184
|
+
"""
|
185
|
+
|
186
|
+
id = NSID(id)
|
187
|
+
groups = self.fetch_entities({'_type': 'organization'})
|
188
|
+
groups.extend(self.fetch_entities({'_type': 'organization', 'owner_id': id}))
|
189
|
+
|
190
|
+
for group in groups:
|
191
|
+
if group is None:
|
192
|
+
groups.remove(group)
|
193
|
+
continue
|
194
|
+
|
195
|
+
if group.owner.id == id:
|
196
|
+
continue
|
197
|
+
|
198
|
+
for member in group.members:
|
199
|
+
if member.id == id:
|
200
|
+
break
|
201
|
+
else:
|
202
|
+
groups.remove(group)
|
203
|
+
|
204
|
+
return [ group for group in groups if group is not None ]
|
205
|
+
|
206
|
+
def get_position(self, id: str) -> Position:
|
207
|
+
"""
|
208
|
+
Récupère une position légale (métier, domaine professionnel).
|
209
|
+
|
210
|
+
## Paramètres
|
211
|
+
id: `str`
|
212
|
+
ID de la position (SENSIBLE À LA CASSE !)
|
213
|
+
|
214
|
+
## Renvoie
|
215
|
+
- `.Position`
|
216
|
+
"""
|
217
|
+
|
218
|
+
_data = self._get_by_ID('positions', id)
|
219
|
+
|
220
|
+
if _data is None:
|
221
|
+
return None
|
222
|
+
|
223
|
+
position = Position(id)
|
224
|
+
position.name = _data['name']
|
225
|
+
position.permissions.edit(dict(zip(_data['permissions'], True)))
|
226
|
+
|
227
|
+
return position
|
228
|
+
|
229
|
+
"""
|
230
|
+
---- ARCHIVES --
|
231
|
+
"""
|
232
|
+
|
233
|
+
def _add_archive(self, archive: Action) -> None:
|
234
|
+
"""
|
235
|
+
Ajoute une archive d'une action (modification au sein d'un groupe ou sanction) dans la base de données.
|
236
|
+
"""
|
237
|
+
|
238
|
+
archive.id = NSID(archive.id)
|
239
|
+
archive.author = NSID(archive.author)
|
240
|
+
archive.target = NSID(archive.target)
|
241
|
+
|
242
|
+
_data = archive.__dict__.copy()
|
243
|
+
|
244
|
+
if type(archive) == Sanction:
|
245
|
+
_data['type'] = "sanction"
|
246
|
+
elif type(archive) == AdminAction:
|
247
|
+
_data['type'] = "adminaction"
|
248
|
+
elif type(archive) == Report:
|
249
|
+
_data['type'] = "report"
|
250
|
+
else:
|
251
|
+
_data['type'] = "unknown"
|
252
|
+
|
253
|
+
self._put_in_db('archives', _data)
|
254
|
+
|
255
|
+
def _get_archive(self, id: str | NSID) -> Action | Sanction | AdminAction:
|
256
|
+
"""
|
257
|
+
Récupère une archive spécifique.
|
258
|
+
|
259
|
+
## Paramètres
|
260
|
+
id: `str | NSID`
|
261
|
+
ID de l'archive.
|
262
|
+
|
263
|
+
## Renvoie
|
264
|
+
- `.Action | .Sanction | .AdminAction`
|
265
|
+
"""
|
266
|
+
|
267
|
+
id = NSID(id)
|
268
|
+
_data = self._get_by_ID('archives', id)
|
269
|
+
|
270
|
+
if _data is None:
|
271
|
+
return None
|
272
|
+
|
273
|
+
if _data['type'] == "sanction": # Mute, ban, GAV, kick, détention, prune (xp seulement)
|
274
|
+
archive = Sanction(_data['author'], _data['target'])
|
275
|
+
|
276
|
+
archive.details = _data['details']
|
277
|
+
archive.major = _data['major']
|
278
|
+
archive.duration = _data['duration']
|
279
|
+
elif _data['type'] == "adminaction": # Renommage, promotion, démotion (au niveau de l'état)
|
280
|
+
archive = AdminAction(_data['author'], _data['target'])
|
281
|
+
|
282
|
+
archive.details = _data['details']
|
283
|
+
archive.new_state = _data['new_state']
|
284
|
+
elif _data['type'] == "report": # Plainte
|
285
|
+
archive = Report(_data['author'], _data['target'])
|
286
|
+
|
287
|
+
archive.details = _data['details']
|
288
|
+
else:
|
289
|
+
archive = Action(_data['author'], _data['target'])
|
290
|
+
|
291
|
+
archive.id = id
|
292
|
+
archive.action = _data['action']
|
293
|
+
archive.date = _data['date']
|
294
|
+
|
295
|
+
return archive
|
296
|
+
|
297
|
+
def _fetch_archives(self, **query) -> list[ Action | Sanction | AdminAction ]:
|
298
|
+
"""
|
299
|
+
Récupère une liste d'archives correspondant à la requête.
|
300
|
+
|
301
|
+
## Paramètres
|
302
|
+
query: `dict`
|
303
|
+
Requête pour filtrer les archives.
|
304
|
+
|
305
|
+
## Renvoie
|
306
|
+
- `list[Action | Sanction | AdminAction]`
|
307
|
+
"""
|
308
|
+
|
309
|
+
_res = self.fetch('archives', **query)
|
310
|
+
|
311
|
+
return [ self._get_archive(archive['key']) for archive in _res ]
|
@@ -0,0 +1,282 @@
|
|
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: `.Vote | .ClosedVote`
|
18
|
+
- Différentes institutions: `.Institutions | .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: str | NSID) -> Vote | ClosedVote | Lawsuit:
|
30
|
+
"""
|
31
|
+
Récupère un vote spécifique.
|
32
|
+
|
33
|
+
## Paramètres
|
34
|
+
id: `str | NSID`\n
|
35
|
+
ID du vote.
|
36
|
+
|
37
|
+
## Renvoie
|
38
|
+
- `.Vote | .ClosedVote`
|
39
|
+
"""
|
40
|
+
|
41
|
+
id = NSID(id)
|
42
|
+
_data = self._get_by_ID('votes', id)
|
43
|
+
|
44
|
+
if _data is None:
|
45
|
+
return None
|
46
|
+
|
47
|
+
if _data['_type'] == 'open':
|
48
|
+
vote = Vote(id, _data['title'], tuple(_data['choices'].keys()))
|
49
|
+
elif _data['_type'] == 'closed':
|
50
|
+
vote = ClosedVote(id, _data['title'])
|
51
|
+
elif _data['_type'] == 'lawsuit':
|
52
|
+
vote = Lawsuit(id, _data['title'])
|
53
|
+
else:
|
54
|
+
vote = Vote('0', 'Unknown Vote', ())
|
55
|
+
|
56
|
+
vote.author = _data['author']
|
57
|
+
vote.startDate = _data['startDate']
|
58
|
+
vote.endDate = _data['endDate']
|
59
|
+
vote.choices = _data['choices']
|
60
|
+
|
61
|
+
return vote
|
62
|
+
|
63
|
+
def save_vote(self, vote: Vote | ClosedVote) -> None:
|
64
|
+
"""Sauvegarde un vote dans la base de données."""
|
65
|
+
|
66
|
+
vote.id = NSID(vote.id)
|
67
|
+
|
68
|
+
_data = {
|
69
|
+
'_type':'open' if type(vote) == Vote else\
|
70
|
+
'closed' if type(vote) == ClosedVote else\
|
71
|
+
'lawsuit' if type(vote) == Lawsuit else\
|
72
|
+
'unknown',
|
73
|
+
'title': vote.title,
|
74
|
+
'author': NSID(vote.author),
|
75
|
+
'startDate': vote.startDate,
|
76
|
+
'endDate': vote.endDate,
|
77
|
+
'choices': vote.choices
|
78
|
+
}
|
79
|
+
|
80
|
+
self._put_in_db('votes', _data)
|
81
|
+
|
82
|
+
# Aucune possibilité de supprimer un vote
|
83
|
+
|
84
|
+
"""
|
85
|
+
---- INSTITUTION & MANDAT ----
|
86
|
+
"""
|
87
|
+
|
88
|
+
def get_official(self, id: str | NSID, current_mandate: bool = True) -> Official:
|
89
|
+
"""
|
90
|
+
Récupère les informations d'un fonctionnaire (mandats, contributions).
|
91
|
+
|
92
|
+
## Paramètres
|
93
|
+
id: `str | NSID`\n
|
94
|
+
ID du fonctionnaire.
|
95
|
+
current_mandate: `bool`\n
|
96
|
+
Indique si l'on doit récupérer le mandat actuel ou les anciens mandats.
|
97
|
+
|
98
|
+
## Renvoie
|
99
|
+
- `.Official`
|
100
|
+
"""
|
101
|
+
|
102
|
+
id = NSID(id)
|
103
|
+
|
104
|
+
base = 'mandate' if current_mandate else 'archives'
|
105
|
+
|
106
|
+
_contributions = self.fetch(base, {'author': id, 'type': 'contrib'})
|
107
|
+
_mandates = self.fetch(base, {'target': id, 'type': 'election'}) +\
|
108
|
+
self.fetch(base, {'target': id, 'type': 'promotion'})
|
109
|
+
|
110
|
+
user = Official(id)
|
111
|
+
for mandate in _mandates:
|
112
|
+
if mandate['position'].startswith('MIN'):
|
113
|
+
mandate['position'] = 'MIN'
|
114
|
+
|
115
|
+
try:
|
116
|
+
user.mandates[mandate['position']] += 1
|
117
|
+
except KeyError:
|
118
|
+
user.mandates[mandate['position']] = 1
|
119
|
+
|
120
|
+
for contrib in _contributions:
|
121
|
+
try:
|
122
|
+
user.contributions[contrib['action']] += 1
|
123
|
+
except KeyError:
|
124
|
+
user.contributions[contrib['action']] = 1
|
125
|
+
|
126
|
+
return user
|
127
|
+
|
128
|
+
def get_institutions(self) -> State:
|
129
|
+
"""Récupère l'état actuel des institutions de la république."""
|
130
|
+
|
131
|
+
admin = Administration()
|
132
|
+
gov = Government(Official('0'))
|
133
|
+
assembly = Assembly()
|
134
|
+
court = Court()
|
135
|
+
police_forces = PoliceForces()
|
136
|
+
|
137
|
+
_get_position: list[dict] = lambda pos : self._select_from_db('functions', 'id', pos)['users']
|
138
|
+
|
139
|
+
admin.members = [ self.get_official(user['id']) for user in _get_position('ADMIN') ]
|
140
|
+
admin.president = self.get_official('F7DB60DD1C4300A') # happex (remplace Kheops pour l'instant)
|
141
|
+
|
142
|
+
gov.president = self.get_official([0])
|
143
|
+
|
144
|
+
minister = lambda code : self.get_official(_get_position(f'MIN_{code}')[0]['id'])
|
145
|
+
gov.prime_minister = minister('PRIM')
|
146
|
+
gov.economy_minister = minister('ECO')
|
147
|
+
gov.inner_minister = minister('INN')
|
148
|
+
gov.press_minister = minister('AUD')
|
149
|
+
gov.justice_minister = minister('JUS')
|
150
|
+
gov.outer_minister = minister('OUT')
|
151
|
+
|
152
|
+
assembly.president = self.get_official(_get_position('PRE_AS')[0])
|
153
|
+
assembly.members = [ self.get_official(user['id']) for user in _get_position('REPR') ]
|
154
|
+
|
155
|
+
court.president = gov.justice_minister
|
156
|
+
court.members = [ self.get_official(user['id']) for user in _get_position('JUDGE') ]
|
157
|
+
|
158
|
+
police_forces.president = gov.inner_minister
|
159
|
+
police_forces.members = [ self.get_official(user['id']) for user in _get_position('POLICE') ]
|
160
|
+
|
161
|
+
instits = State()
|
162
|
+
instits.administration = admin
|
163
|
+
instits.government = gov
|
164
|
+
instits.court = court
|
165
|
+
instits.assembly = assembly
|
166
|
+
instits.police = police_forces
|
167
|
+
|
168
|
+
return instits
|
169
|
+
|
170
|
+
def update_institutions(self, institutions: State):
|
171
|
+
"""
|
172
|
+
Fonction communément appelée après un vote législatif ou une nomination.\n
|
173
|
+
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
|
174
|
+
|
175
|
+
## Paramètres
|
176
|
+
institutions: `.Institutions`\n
|
177
|
+
Le nouvel état des institutions, à sauvegarder.
|
178
|
+
"""
|
179
|
+
|
180
|
+
get_ids = lambda institution : [ member.id for member in institutions.__getattribute__(institution).members ]
|
181
|
+
|
182
|
+
self._put_in_db('functions', { 'users': get_ids('administration') })
|
183
|
+
self._put_in_db('functions', { 'users': get_ids('assembly') })
|
184
|
+
self._put_in_db('functions', { 'users': get_ids('court') })
|
185
|
+
self._put_in_db('functions', { 'users': get_ids('police') })
|
186
|
+
|
187
|
+
self._put_in_db('functions', { 'users': [ institutions.assembly.president.id ] })
|
188
|
+
self._put_in_db('functions', { 'users': [ institutions.government.president.id ] })
|
189
|
+
|
190
|
+
self._put_in_db('functions', { 'users': [ institutions.government.prime_minister.id ] })
|
191
|
+
self._put_in_db('functions', { 'users': [ institutions.government.inner_minister.id ] })
|
192
|
+
self._put_in_db('functions', { 'users': [ institutions.government.justice_minister.id ] })
|
193
|
+
self._put_in_db('functions', { 'users': [ institutions.government.economy_minister.id ] })
|
194
|
+
self._put_in_db('functions', { 'users': [ institutions.government.press_minister.id ] })
|
195
|
+
self._put_in_db('functions', { 'users': [ institutions.government.outer_minister.id ] })
|
196
|
+
|
197
|
+
def new_mandate(self, institutions: State, weeks: int = 4) -> None:
|
198
|
+
"""
|
199
|
+
Fonction qui amène à supprimer toutes les archives du mandat précédent
|
200
|
+
"""
|
201
|
+
|
202
|
+
for item in self.fetch('mandate'):
|
203
|
+
if item['date'] >= round(time.time()) - weeks * 604800: # On évite de supprimer les informations écrites lors de la période définie
|
204
|
+
self._delete_by_ID('mandate', item['id'])
|
205
|
+
|
206
|
+
self.update_institutions(institutions)
|
207
|
+
|
208
|
+
"""
|
209
|
+
---- ARCHIVES ----
|
210
|
+
"""
|
211
|
+
|
212
|
+
def _add_archive(self, archive: Action) -> None:
|
213
|
+
"""Ajoute une archive d'une action (élection, promotion, ou rétrogradation) dans la base de données."""
|
214
|
+
|
215
|
+
archive.id = NSID(archive.id)
|
216
|
+
_data = archive.__dict__.copy()
|
217
|
+
|
218
|
+
if type(archive) == Election:
|
219
|
+
_data['type'] = "election"
|
220
|
+
elif type(archive) == Promotion:
|
221
|
+
_data['type'] = "promotion"
|
222
|
+
elif type(archive) == Demotion:
|
223
|
+
_data['type'] = "demotion"
|
224
|
+
else:
|
225
|
+
_data['type'] = "unknown"
|
226
|
+
|
227
|
+
self._put_in_db('archives', _data)
|
228
|
+
self._put_in_db('mandate', _data) # Ajouter les archives à celle du mandat actuel
|
229
|
+
|
230
|
+
def _get_archive(self, id: str | NSID) -> Action | Election | Promotion | Demotion:
|
231
|
+
"""
|
232
|
+
Récupère une archive spécifique.
|
233
|
+
|
234
|
+
## Paramètres
|
235
|
+
id: `str | NSID`\n
|
236
|
+
ID de l'archive.
|
237
|
+
|
238
|
+
## Renvoie
|
239
|
+
- `.Action | .Election | .Promotion | .Demotion`
|
240
|
+
"""
|
241
|
+
|
242
|
+
id = NSID(id)
|
243
|
+
_data = self._get_by_ID('archives', id)
|
244
|
+
|
245
|
+
if _data is None:
|
246
|
+
return None
|
247
|
+
|
248
|
+
if _data['type'] == "election":
|
249
|
+
archive = Election(_data['author'], _data['target'], _data['position'])
|
250
|
+
|
251
|
+
archive.positive_votes = _data['positive_votes']
|
252
|
+
archive.total_votes = _data['total_votes']
|
253
|
+
elif _data['type'] == "promotion":
|
254
|
+
archive = Promotion(_data['author'], _data['target'], _data['position'])
|
255
|
+
elif _data['type'] == "demotion":
|
256
|
+
archive = Demotion(_data['author'], _data['target'])
|
257
|
+
|
258
|
+
archive.reason = _data['reason']
|
259
|
+
else:
|
260
|
+
archive = Action(_data['author'], _data['target'])
|
261
|
+
|
262
|
+
archive.id = id
|
263
|
+
archive.action = _data['action']
|
264
|
+
archive.date = _data['date']
|
265
|
+
|
266
|
+
return archive
|
267
|
+
|
268
|
+
def _fetch_archives(self, **query) -> list[ Action | Election | Promotion | Demotion ]:
|
269
|
+
"""
|
270
|
+
Récupère une liste d'archives correspondant à la requête.
|
271
|
+
|
272
|
+
## Paramètres
|
273
|
+
query: `dict`
|
274
|
+
Requête pour filtrer les archives.
|
275
|
+
|
276
|
+
## Renvoie
|
277
|
+
- `list[Action | Election | Promotion | Demotion]`
|
278
|
+
"""
|
279
|
+
|
280
|
+
_res = self.fetch('archives', **query)
|
281
|
+
|
282
|
+
return [ self._get_archive(archive['key']) for archive in _res ]
|
nsarchive/utils/assets.py
CHANGED
@@ -2,7 +2,7 @@ import io
|
|
2
2
|
import os
|
3
3
|
from PIL import Image
|
4
4
|
|
5
|
-
def open(path: str) ->
|
5
|
+
def open(path: str) -> bytes:
|
6
6
|
curr_dir = os.path.dirname(os.path.abspath(os.path.join(__file__)))
|
7
7
|
parent_dir = os.path.dirname(curr_dir)
|
8
8
|
asset_path = os.path.join(parent_dir, 'assets', path)
|
@@ -1,7 +1,7 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: nsarchive
|
3
|
-
Version:
|
4
|
-
Summary:
|
3
|
+
Version: 2.0.0a1
|
4
|
+
Summary: API-wrapper pour récupérer des données liées à Nation
|
5
5
|
License: GPL-3.0
|
6
6
|
Author: happex
|
7
7
|
Author-email: 110610727+okayhappex@users.noreply.github.com
|
@@ -11,8 +11,8 @@ 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
|
-
Requires-Dist: deta (>=1.2,<2.0)
|
15
14
|
Requires-Dist: pillow (>=10.4,<11.0)
|
15
|
+
Requires-Dist: supabase (>=2.9.1,<3.0.0)
|
16
16
|
Description-Content-Type: text/markdown
|
17
17
|
|
18
18
|
# nsarchive
|
@@ -0,0 +1,16 @@
|
|
1
|
+
nsarchive/__init__.py,sha256=-yXGGJBOkoQo-6Vg6hJVIqr-C7sQyL_LaYcQ3yx9aFs,696
|
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=jJOsGgnURxR8YwJiIHgodPOmJ31LOtYDVbz33kIM5Yg,3512
|
5
|
+
nsarchive/cls/economy.py,sha256=-eV8R5KMXSeXcKEu2G8OP1UgYgb0X6uks0aD2XhlbcU,1220
|
6
|
+
nsarchive/cls/entities.py,sha256=i7tlx-fDpwGWsnGgpXrLcASLHYQjf1dXUCdr1mKc4Ik,6629
|
7
|
+
nsarchive/cls/exceptions.py,sha256=QN6Qn7cxTkGoC4lO50hBAq4gZCgo7scQvCkb-xKl6Xs,692
|
8
|
+
nsarchive/cls/republic.py,sha256=F6il2FrvCoutHxQlW3xM36GaFfIqdorg2jicMAlPdUo,2503
|
9
|
+
nsarchive/instances/_economy.py,sha256=uZnuZadvZHZ9NwalIxJY0X25b_ubi7LU7A9DKwU_Wtc,6454
|
10
|
+
nsarchive/instances/_entities.py,sha256=Xgdnctt1NiqxG4c0VozxKFj_X-hlm3EOc5T1TUk6OdQ,10332
|
11
|
+
nsarchive/instances/_republic.py,sha256=yN7Pj7KdenPwIafv3_vfsd-fHXyN206qr8e-lEbBuQo,10168
|
12
|
+
nsarchive/utils/assets.py,sha256=WGC03K1VZ5LwGzcVXbqphtGBZ_Vjso-1hmbIkpgL_X8,382
|
13
|
+
nsarchive-2.0.0a1.dist-info/LICENSE,sha256=aFLFZg6LEJFpTlNQ8su3__jw4GfV-xWBmC1cePkKZVw,35802
|
14
|
+
nsarchive-2.0.0a1.dist-info/METADATA,sha256=jDqBAFWTbkYtZQyuouXixJxO6HAv8bUX3K-dgeWFdOY,5697
|
15
|
+
nsarchive-2.0.0a1.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
16
|
+
nsarchive-2.0.0a1.dist-info/RECORD,,
|
nsarchive-1.4.0.dist-info/RECORD
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
nsarchive/__init__.py,sha256=85kvYTT-TSJgTX1AX-nVNI9GJANJS4S6UXCE3SpyUjE,27563
|
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=7vhD6r6DuvTlyGyPmm1scpWFsqPGMUw7JQ9Ks8sHWpQ,6712
|
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.4.0.dist-info/LICENSE,sha256=aFLFZg6LEJFpTlNQ8su3__jw4GfV-xWBmC1cePkKZVw,35802
|
11
|
-
nsarchive-1.4.0.dist-info/METADATA,sha256=MK4hOKyqSERSJtko967gMBPPdnzyqY-GFfx5pzaimts,5629
|
12
|
-
nsarchive-1.4.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
13
|
-
nsarchive-1.4.0.dist-info/RECORD,,
|
File without changes
|
File without changes
|