nsarchive 3.0.0a7__py3-none-any.whl → 3.0.0a8__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 +15 -10
- nsarchive/{instances → interfaces}/_economy.py +15 -30
- nsarchive/interfaces/_entities.py +206 -0
- nsarchive/interfaces/_justice.py +50 -0
- nsarchive/interfaces/_state.py +142 -0
- nsarchive/mandate.py +50 -0
- nsarchive/{cls → models}/base.py +23 -5
- nsarchive/{cls → models}/economy.py +34 -13
- nsarchive/{cls → models}/entities.py +139 -72
- nsarchive/models/justice.py +108 -0
- nsarchive/models/republic.py +125 -0
- nsarchive/models/scale.py +23 -0
- nsarchive/models/state.py +59 -0
- {nsarchive-3.0.0a7.dist-info → nsarchive-3.0.0a8.dist-info}/METADATA +3 -2
- nsarchive-3.0.0a8.dist-info/RECORD +19 -0
- {nsarchive-3.0.0a7.dist-info → nsarchive-3.0.0a8.dist-info}/WHEEL +1 -1
- nsarchive/cls/archives.py +0 -93
- nsarchive/cls/republic.py +0 -149
- nsarchive/instances/_entities.py +0 -281
- nsarchive/instances/_republic.py +0 -339
- nsarchive-3.0.0a7.dist-info/RECORD +0 -15
- {nsarchive-3.0.0a7.dist-info → nsarchive-3.0.0a8.dist-info}/LICENSE +0 -0
@@ -0,0 +1,125 @@
|
|
1
|
+
import requests
|
2
|
+
import time
|
3
|
+
|
4
|
+
from .base import NSID
|
5
|
+
|
6
|
+
# Votes
|
7
|
+
|
8
|
+
class VoteOption:
|
9
|
+
"""
|
10
|
+
Option disponible lors d'un vote
|
11
|
+
|
12
|
+
## Attributs
|
13
|
+
- id: `str`\n
|
14
|
+
Identifiant de l'option
|
15
|
+
- title: `str`\n
|
16
|
+
Label de l'option
|
17
|
+
- count: `int`\n
|
18
|
+
Nombre de sympathisants pour cette option
|
19
|
+
"""
|
20
|
+
|
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
|
25
|
+
|
26
|
+
class Vote:
|
27
|
+
"""
|
28
|
+
Classe de référence pour les différents votes du serveur
|
29
|
+
|
30
|
+
## Attributs
|
31
|
+
- id: `NSID`\n
|
32
|
+
Identifiant du vote
|
33
|
+
- title: `str`\n
|
34
|
+
Titre du vote
|
35
|
+
- options: list[.VoteOption]\n
|
36
|
+
Liste des choix disponibles
|
37
|
+
- author: `NSID`\n
|
38
|
+
Identifiant de l'auteur du vote
|
39
|
+
- startDate: `int`\n
|
40
|
+
Date de début du vote
|
41
|
+
- endDate: `int`\n
|
42
|
+
Date limite pour voter
|
43
|
+
"""
|
44
|
+
|
45
|
+
def __init__(self, id: NSID = None) -> None:
|
46
|
+
self._url: str
|
47
|
+
self._headers: dict
|
48
|
+
|
49
|
+
self.id: NSID = id if id else NSID(0)
|
50
|
+
self.title: str = ''
|
51
|
+
self.author: NSID = NSID(0)
|
52
|
+
|
53
|
+
self.startDate: int = round(time.time())
|
54
|
+
self.endDate: int = 0
|
55
|
+
|
56
|
+
self.options: list[VoteOption] = []
|
57
|
+
|
58
|
+
def _load(self, _data: dict, url: str, headers: dict) -> None:
|
59
|
+
self._url = url + '/votes/' + _data['id']
|
60
|
+
self._headers = headers
|
61
|
+
|
62
|
+
self.id = NSID(_data['id'])
|
63
|
+
self.title = _data['title']
|
64
|
+
self.author = _data['author_id']
|
65
|
+
|
66
|
+
self.startDate = _data['start_date']
|
67
|
+
self.endDate = _data['end_date']
|
68
|
+
|
69
|
+
self.options = []
|
70
|
+
|
71
|
+
for opt in _data['options']:
|
72
|
+
option = VoteOption(opt["id"], opt["title"])
|
73
|
+
option.count = opt["count"]
|
74
|
+
|
75
|
+
self.options.append(option)
|
76
|
+
|
77
|
+
def get(self, id: str) -> VoteOption:
|
78
|
+
for opt in self.options:
|
79
|
+
if opt.id == id:
|
80
|
+
return opt
|
81
|
+
else:
|
82
|
+
raise ValueError(f"Option {id} not found in vote {self.id}")
|
83
|
+
|
84
|
+
def add_vote(self, id: str):
|
85
|
+
"""
|
86
|
+
Ajoute un vote à l'option spécifiée
|
87
|
+
"""
|
88
|
+
|
89
|
+
res = requests.post(f"{self._url}/vote?choice={id}", headers = self._headers)
|
90
|
+
|
91
|
+
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}")
|
98
|
+
else:
|
99
|
+
res.raise_for_status()
|
100
|
+
|
101
|
+
def close(self):
|
102
|
+
"""
|
103
|
+
Ferme le vote
|
104
|
+
"""
|
105
|
+
|
106
|
+
res = requests.post(f"{self._url}/close", headers = self._headers)
|
107
|
+
|
108
|
+
if res.status_code == 200:
|
109
|
+
self.endDate = round(time.time())
|
110
|
+
else:
|
111
|
+
res.raise_for_status()
|
112
|
+
|
113
|
+
class LawsuitVote(Vote):
|
114
|
+
"""
|
115
|
+
Vote à trois positions pour un procès
|
116
|
+
"""
|
117
|
+
|
118
|
+
def __init__(self, id: NSID, title: str) -> None:
|
119
|
+
super().__init__(id, title)
|
120
|
+
|
121
|
+
self.options = [
|
122
|
+
VoteOption('guilty', 'Coupable'),
|
123
|
+
VoteOption('innocent', 'Innocent'),
|
124
|
+
VoteOption('blank', 'Pas d\'avis'),
|
125
|
+
]
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class Scale:
|
2
|
+
def __init__(self):
|
3
|
+
self.democratie: float = 0.0
|
4
|
+
self.coertition: float = 0.0
|
5
|
+
self.liberte: float = 0.0
|
6
|
+
self.integration: float = 0.0
|
7
|
+
self.revolution: float = 0.0
|
8
|
+
|
9
|
+
def _load(self, _data: dict):
|
10
|
+
self.democratie = _data.get('DEM', 0.0)
|
11
|
+
self.coertition = _data.get('SRV', 0.0)
|
12
|
+
self.liberte = _data.get('LIB', 0.0)
|
13
|
+
self.integration = _data.get('INT', 0.0)
|
14
|
+
self.revolution = _data.get('REV', 0.0)
|
15
|
+
|
16
|
+
def _to_dict(self) -> dict:
|
17
|
+
return {
|
18
|
+
'DEM': self.democratie,
|
19
|
+
'SRV': self.coertition,
|
20
|
+
'LIB': self.liberte,
|
21
|
+
'INT': self.integration,
|
22
|
+
'REV': self.revolution
|
23
|
+
}
|
@@ -0,0 +1,59 @@
|
|
1
|
+
import requests
|
2
|
+
|
3
|
+
from .base import NSID
|
4
|
+
from .republic import Vote
|
5
|
+
|
6
|
+
class Party:
|
7
|
+
def __init__(self, org_id: NSID):
|
8
|
+
self._url: str = ''
|
9
|
+
self._headers: dict = {}
|
10
|
+
|
11
|
+
self.org_id = org_id
|
12
|
+
|
13
|
+
self.color: int = 0x000000
|
14
|
+
self.motto: str = None
|
15
|
+
self.scale: dict = {}
|
16
|
+
self.last_elected: int = None
|
17
|
+
|
18
|
+
def _load(self, _data: dict, url: str = None, headers: dict = None):
|
19
|
+
self._url = url
|
20
|
+
self._headers = headers
|
21
|
+
|
22
|
+
self.org_id = _data['org_id']
|
23
|
+
|
24
|
+
self.color = _data['color']
|
25
|
+
self.motto = _data['motto']
|
26
|
+
self.scale = _data['politiscales']
|
27
|
+
self.last_elected = _data['last_elected']
|
28
|
+
|
29
|
+
class Election:
|
30
|
+
def __init__(self, id: NSID):
|
31
|
+
self._url: str = ''
|
32
|
+
self._headers: dict = {}
|
33
|
+
|
34
|
+
self.id = id
|
35
|
+
self.type: str = 'full' # Partial = législatives, full = totales
|
36
|
+
self.vote: Vote = None
|
37
|
+
|
38
|
+
self.add_vote = self.vote.add_vote
|
39
|
+
self.close = self.vote.close
|
40
|
+
|
41
|
+
def _load(self, _data: dict, url: str = None, headers: str = None):
|
42
|
+
self._url = url
|
43
|
+
self._headers = headers
|
44
|
+
|
45
|
+
self.id = _data['id']
|
46
|
+
self.type = _data['type']
|
47
|
+
self.vote._load(_data['vote'], url, headers)
|
48
|
+
|
49
|
+
def submit_candidacy(self):
|
50
|
+
res = requests.put(f"{self._url}/submit")
|
51
|
+
|
52
|
+
if res.status_code != 200:
|
53
|
+
res.raise_for_status()
|
54
|
+
|
55
|
+
def cancel_candidacy(self):
|
56
|
+
res = requests.put(f"{self._url}/cancel_candidacy")
|
57
|
+
|
58
|
+
if res.status_code != 200:
|
59
|
+
res.raise_for_status()
|
@@ -1,6 +1,6 @@
|
|
1
|
-
Metadata-Version: 2.
|
1
|
+
Metadata-Version: 2.3
|
2
2
|
Name: nsarchive
|
3
|
-
Version: 3.0.
|
3
|
+
Version: 3.0.0a8
|
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,19 @@
|
|
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,,
|
nsarchive/cls/archives.py
DELETED
@@ -1,93 +0,0 @@
|
|
1
|
-
import time
|
2
|
-
|
3
|
-
from .base import *
|
4
|
-
|
5
|
-
class Archive:
|
6
|
-
def __init__(self, author: NSID = '0', target: NSID = '0'):
|
7
|
-
"""
|
8
|
-
Classe de référence pour toutes les archives.
|
9
|
-
|
10
|
-
## Attributs de base
|
11
|
-
- date: `int`\n
|
12
|
-
Date (timestamp) de l'exécution de l'archive
|
13
|
-
- id: `NSID`\n
|
14
|
-
Clé d'identification des archives (basée sur la date)
|
15
|
-
- author: `NSID`\n
|
16
|
-
ID de l'auteur de l'action
|
17
|
-
- target: `NSID`:
|
18
|
-
ID de la cible de l'action
|
19
|
-
- action: `str`:\n
|
20
|
-
Action effectuée
|
21
|
-
- details: `dict`\n
|
22
|
-
Ensemble de détails que les différents bots peuvent utiliser
|
23
|
-
"""
|
24
|
-
self.date: int = round(time.time())
|
25
|
-
|
26
|
-
self.id: NSID = NSID(self.date)
|
27
|
-
self.author: NSID = NSID(author)
|
28
|
-
self.target: NSID = NSID(target)
|
29
|
-
|
30
|
-
self.action: str = ""
|
31
|
-
self.details: dict = {
|
32
|
-
"reason": None
|
33
|
-
}
|
34
|
-
|
35
|
-
|
36
|
-
# Entities
|
37
|
-
|
38
|
-
class Sanction(Archive):
|
39
|
-
def __init__(self, author: NSID, target: NSID) -> None:
|
40
|
-
super().__init__(author, target)
|
41
|
-
|
42
|
-
self.details: dict = {
|
43
|
-
"reason": None,
|
44
|
-
"major": False, # Sanction majeure ou non
|
45
|
-
"duration": 0 # Durée en secondes , 0 = définitif
|
46
|
-
}
|
47
|
-
|
48
|
-
class Report(Archive):
|
49
|
-
def __init__(self, author: NSID, target: NSID) -> None:
|
50
|
-
super().__init__(author, target)
|
51
|
-
|
52
|
-
self.details: dict = {
|
53
|
-
"reason": None,
|
54
|
-
"elements": [] # Liste des pièces jointes
|
55
|
-
}
|
56
|
-
|
57
|
-
|
58
|
-
# Community
|
59
|
-
|
60
|
-
class Election(Archive):
|
61
|
-
def __init__(self, author: NSID, target: NSID, position: str) -> None:
|
62
|
-
super().__init__(author, target)
|
63
|
-
|
64
|
-
self.details = {
|
65
|
-
"position": position,
|
66
|
-
"positive_votes": 0,
|
67
|
-
"total_votes": 0
|
68
|
-
}
|
69
|
-
|
70
|
-
class Promotion(Archive):
|
71
|
-
def __init__(self, author: NSID, target: NSID, position: str) -> None:
|
72
|
-
super().__init__(author, target)
|
73
|
-
|
74
|
-
self.details = {
|
75
|
-
"position": position
|
76
|
-
}
|
77
|
-
|
78
|
-
class Demotion(Archive):
|
79
|
-
def __init__(self, author: NSID, target: NSID) -> None:
|
80
|
-
super().__init__(author, target)
|
81
|
-
|
82
|
-
|
83
|
-
# Bank
|
84
|
-
|
85
|
-
class Transaction(Archive):
|
86
|
-
def __init__(self, author: NSID, target: NSID) -> None:
|
87
|
-
super().__init__(author, target)
|
88
|
-
|
89
|
-
self.details = {
|
90
|
-
"amount": 0,
|
91
|
-
"currency": "HC",
|
92
|
-
"reason": None
|
93
|
-
}
|
nsarchive/cls/republic.py
DELETED
@@ -1,149 +0,0 @@
|
|
1
|
-
from nsarchive.cls.base import NSID
|
2
|
-
|
3
|
-
# Votes
|
4
|
-
|
5
|
-
class VoteOption:
|
6
|
-
"""
|
7
|
-
Option disponible lors d'un vote
|
8
|
-
|
9
|
-
## Attributs
|
10
|
-
- id: `str`\n
|
11
|
-
Identifiant de l'option
|
12
|
-
- title: `str`\n
|
13
|
-
Label de l'option
|
14
|
-
- count: `int`\n
|
15
|
-
Nombre de sympathisants pour cette option
|
16
|
-
"""
|
17
|
-
|
18
|
-
def __init__(self, id: str, title: str = None, count: int = 0):
|
19
|
-
self.id = id
|
20
|
-
self.title = title if title else id
|
21
|
-
self.count = count
|
22
|
-
|
23
|
-
class Vote:
|
24
|
-
"""
|
25
|
-
Classe de référence pour les différents votes du serveur
|
26
|
-
|
27
|
-
## Attributs
|
28
|
-
- id: `NSID`\n
|
29
|
-
Identifiant du vote
|
30
|
-
- title: `str`\n
|
31
|
-
Titre du vote
|
32
|
-
- choices: list[.VoteOption]\n
|
33
|
-
Liste des choix disponibles
|
34
|
-
- author: `NSID`\n
|
35
|
-
Identifiant de l'auteur du vote
|
36
|
-
- startDate: `int`\n
|
37
|
-
Date de début du vote
|
38
|
-
- endDate: `int`\n
|
39
|
-
Date limite pour voter
|
40
|
-
"""
|
41
|
-
|
42
|
-
def __init__(self, id: NSID, title: str) -> None:
|
43
|
-
self.id: NSID = NSID(id)
|
44
|
-
self.title: str = title
|
45
|
-
self.choices: list[VoteOption] = []
|
46
|
-
self.author: NSID = NSID("0")
|
47
|
-
self.startDate: int = 0
|
48
|
-
self.endDate: int = 0
|
49
|
-
|
50
|
-
def by_id(self, id: str) -> VoteOption:
|
51
|
-
for opt in self.choices:
|
52
|
-
if opt.id == id:
|
53
|
-
return opt
|
54
|
-
|
55
|
-
def sorted(self, titles_only: bool = False) -> list[VoteOption] | list[str]:
|
56
|
-
sorted_list: list[VoteOption] = sorted(self.choices, lambda opt : opt.count)
|
57
|
-
|
58
|
-
if titles_only:
|
59
|
-
return [ opt.id for opt in sorted_list ]
|
60
|
-
else:
|
61
|
-
return sorted_list
|
62
|
-
|
63
|
-
class Referendum(Vote):
|
64
|
-
"""
|
65
|
-
Vote à trois positions
|
66
|
-
"""
|
67
|
-
|
68
|
-
def __init__(self, id: NSID, title: str) -> None:
|
69
|
-
super().__init__(id, title)
|
70
|
-
|
71
|
-
self.choices = [
|
72
|
-
VoteOption('yes', 'Oui'),
|
73
|
-
VoteOption('no', 'Non'),
|
74
|
-
VoteOption('blank', 'Pas d\'avis'),
|
75
|
-
]
|
76
|
-
|
77
|
-
class Lawsuit(Vote):
|
78
|
-
"""
|
79
|
-
Vote à trois positions pour un procès
|
80
|
-
"""
|
81
|
-
|
82
|
-
def __init__(self, id: NSID, title: str) -> None:
|
83
|
-
super().__init__(id, title)
|
84
|
-
|
85
|
-
self.choices = [
|
86
|
-
VoteOption('guilty', 'Coupable'),
|
87
|
-
VoteOption('innocent', 'Innocent'),
|
88
|
-
VoteOption('blank', 'Pas d\'avis'),
|
89
|
-
]
|
90
|
-
|
91
|
-
|
92
|
-
# Institutions (defs)
|
93
|
-
|
94
|
-
class Official:
|
95
|
-
def __init__(self, id: NSID) -> None:
|
96
|
-
self.id: NSID = NSID(id)
|
97
|
-
|
98
|
-
self.mandates: int = {
|
99
|
-
'PRE_REP': 0, # Président de la République
|
100
|
-
'MIN': 0, # Différents ministres
|
101
|
-
'PRE_AS': 0, # Président de l'Assemblée Nationale
|
102
|
-
'REPR': 0 # Député
|
103
|
-
}
|
104
|
-
|
105
|
-
self.contributions: dict = {
|
106
|
-
'propose_project': 0,
|
107
|
-
'success_project': 0,
|
108
|
-
'vote_law': 0
|
109
|
-
}
|
110
|
-
|
111
|
-
class Administration:
|
112
|
-
def __init__(self) -> None:
|
113
|
-
self.president: Official
|
114
|
-
self.members: list[Official] = []
|
115
|
-
|
116
|
-
class Government:
|
117
|
-
def __init__(self, president: Official) -> None:
|
118
|
-
self.president: Official = president
|
119
|
-
self.prime_minister: Official
|
120
|
-
|
121
|
-
self.inner_minister: Official
|
122
|
-
self.economy_minister: Official
|
123
|
-
self.justice_minister: Official
|
124
|
-
self.press_minister: Official
|
125
|
-
self.outer_minister: Official
|
126
|
-
|
127
|
-
class Court:
|
128
|
-
def __init__(self) -> None:
|
129
|
-
self.president: Official
|
130
|
-
# On discutera de la mise en place d'un potentiel président. Pour l'instant c'est le Ministre de la Justice
|
131
|
-
self.members: list[Official] = []
|
132
|
-
|
133
|
-
class Assembly:
|
134
|
-
def __init__(self) -> None:
|
135
|
-
self.president: Official
|
136
|
-
self.members: list[Official] = []
|
137
|
-
|
138
|
-
class PoliceForces:
|
139
|
-
def __init__(self) -> None:
|
140
|
-
self.president: Official
|
141
|
-
self.members: list[Official] = []
|
142
|
-
|
143
|
-
class State:
|
144
|
-
def __init__(self) -> None:
|
145
|
-
self.administration: Administration
|
146
|
-
self.government: Government
|
147
|
-
self.court: Court
|
148
|
-
self.assembly: Assembly
|
149
|
-
self.police: PoliceForces
|