1
|
|
|
#!/usr/bin/env python |
2
|
|
|
# -*- coding: utf-8 -*- |
3
|
|
|
"""A set of dataclasses concerning roles of persons and their particulars.""" |
4
|
|
|
|
5
|
|
|
import os |
6
|
|
|
import sys |
7
|
|
|
from dataclasses import dataclass, field |
8
|
|
|
from typing import List, Set |
9
|
|
|
|
10
|
|
|
PACKAGE_PARENT = ".." |
11
|
|
|
SCRIPT_DIR = os.path.dirname( |
12
|
|
|
os.path.realpath(os.path.join(os.getcwd(), os.path.expanduser(__file__))) |
13
|
|
|
) # isort:skip # noqa # pylint: disable=wrong-import-position |
14
|
|
|
sys.path.append( |
15
|
|
|
os.path.normpath(os.path.join(SCRIPT_DIR, PACKAGE_PARENT)) |
16
|
|
|
) # isort: skip # noqa # pylint: disable=wrong-import-position |
17
|
|
|
|
18
|
|
|
from personroles.politician_role import Politician # type: ignore # noqa |
19
|
|
|
from personroles.resources.helpers import AttrDisplay # type: ignore # noqa |
20
|
|
|
from personroles.resources.helpers import NotInRange # type: ignore # noqa |
21
|
|
|
from personroles.resources.mop_tinyDB import MopsDB # type: ignore # noqa |
22
|
|
|
|
23
|
|
|
|
24
|
|
|
@dataclass |
|
|
|
|
25
|
|
|
class _MoP_default: |
26
|
|
|
key: str = field(default="") # noqa |
27
|
|
|
parl_pres: bool = field(default=False) |
28
|
|
|
parl_vicePres: bool = field(default=False) |
|
|
|
|
29
|
|
|
parliament_entry: str = field(default="unknown") # date string: "11.3.2015" # noqa |
30
|
|
|
parliament_exit: str = field(default="unknown") # dto. |
31
|
|
|
speeches: List[str] = field( |
32
|
|
|
default_factory=lambda: [] |
33
|
|
|
) # identifiers for speeches # noqa |
34
|
|
|
reactions: List[str] = field( |
35
|
|
|
default_factory=lambda: [] |
36
|
|
|
) # identifiers for reactions |
37
|
|
|
membership: Set[str] = field( |
38
|
|
|
default_factory=lambda: set() |
|
|
|
|
39
|
|
|
) # years like ["2010", "2011", ...] |
40
|
|
|
|
41
|
|
|
|
42
|
|
|
@dataclass |
|
|
|
|
43
|
|
|
class _MoP_base: |
44
|
|
|
legislature: str |
45
|
|
|
state: str |
46
|
|
|
|
47
|
|
|
|
48
|
|
|
@dataclass |
|
|
|
|
49
|
|
|
class MoP(_MoP_default, Politician, _MoP_base, AttrDisplay): |
50
|
|
|
|
51
|
|
|
""" |
52
|
|
|
Module mop_role.py covers the role as member of parliament. The role |
53
|
|
|
integrates the role of politician and adds a federal state (like "NRW" or |
54
|
|
|
"BY") and legislature (legislative term) as obligatory informations to |
55
|
|
|
define the role. More informations like speeches held or offices (like |
56
|
|
|
president) filled can be added. Call politician's __post_init__ to |
57
|
|
|
initialize wards and voters. |
58
|
|
|
""" |
59
|
|
|
|
60
|
|
|
def __post_init__(self): |
61
|
|
|
""" |
62
|
|
|
Check if legislature is correct for NRW and add legislature into the |
63
|
|
|
mop's list of memberships (in case more than one term is spent in |
64
|
|
|
parliament. |
65
|
|
|
""" |
66
|
|
|
if int(self.legislature) not in range(14, 18): |
|
|
|
|
67
|
|
|
raise NotInRange("Number for legislature not in range") |
68
|
|
|
else: |
69
|
|
|
self.membership.add(self.legislature) |
70
|
|
|
Politician.__post_init__(self) |
71
|
|
|
|
72
|
|
|
|
73
|
|
|
if __name__ == "__main__": |
74
|
|
|
|
75
|
|
|
mop = MoP( |
76
|
|
|
"14", |
77
|
|
|
"NRW", |
78
|
|
|
"SPD", # type: ignore |
79
|
|
|
"Tom", # type: ignore |
80
|
|
|
"Schwadronius", |
81
|
|
|
party_entry="1990", # type: ignore |
82
|
|
|
peer_title="Junker von", |
83
|
|
|
date_of_birth="1950", |
84
|
|
|
) |
85
|
|
|
print(mop) |
86
|
|
|
|
87
|
|
|
mop.add_Party("Grüne", party_entry="30.11.1999") |
88
|
|
|
mop.change_ward("Düsseldorf II") |
89
|
|
|
print(mop) |
90
|
|
|
|
91
|
|
|
print(mop.__dict__) |
92
|
|
|
|
93
|
|
|
mop_db = MopsDB(".") |
94
|
|
|
mop_key = mop_db.join(mop) |
95
|
|
|
print(mop_db.fetch(mop_key)) |
96
|
|
|
|
This check looks for invalid names for a range of different identifiers.
You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.
If your project includes a Pylint configuration file, the settings contained in that file take precedence.
To find out more about Pylint, please refer to their site.