1
|
|
|
#!/usr/bin/env python |
2
|
|
|
# -*- coding: utf-8 -*- |
3
|
|
|
""" |
4
|
|
|
A set of dataclasses concerning roles of persons and their particulars. |
5
|
|
|
""" |
6
|
|
|
import os |
7
|
|
|
import sys |
8
|
|
|
from dataclasses import dataclass, field |
9
|
|
|
from typing import List, Set |
10
|
|
|
|
11
|
|
|
PACKAGE_PARENT = ".." |
12
|
|
|
SCRIPT_DIR = os.path.dirname( |
13
|
|
|
os.path.realpath(os.path.join(os.getcwd(), os.path.expanduser(__file__))) |
14
|
|
|
) # isort:skip # noqa # pylint: disable=wrong-import-position |
15
|
|
|
sys.path.append( |
16
|
|
|
os.path.normpath(os.path.join(SCRIPT_DIR, PACKAGE_PARENT)) |
17
|
|
|
) # isort: skip # noqa # pylint: disable=wrong-import-position |
18
|
|
|
|
19
|
|
|
from person import Politician # type: ignore # noqa |
20
|
|
|
from src.resources.helpers import ( # type: ignore # noqa |
21
|
|
|
AttrDisplay, |
22
|
|
|
NotInRange, |
23
|
|
|
) |
24
|
|
|
|
25
|
|
|
|
26
|
|
|
@dataclass |
27
|
|
|
class _MoP_default: |
28
|
|
|
parl_pres: bool = field(default=False) |
29
|
|
|
parl_vicePres: bool = field(default=False) |
30
|
|
|
parliament_entry: str = field(default="unknown") # date string: "11.3.2015" # noqa |
31
|
|
|
parliament_exit: str = field(default="unknown") # dto. |
32
|
|
|
speeches: List[str] = field( |
33
|
|
|
default_factory=lambda: [] |
34
|
|
|
) # identifiers for speeches # noqa |
35
|
|
|
reactions: List[str] = field( |
36
|
|
|
default_factory=lambda: [] |
37
|
|
|
) # identifiers for reactions |
38
|
|
|
membership: Set[str] = field( |
39
|
|
|
default_factory=lambda: set() |
40
|
|
|
) # years like ["2010", "2011", ...] |
41
|
|
|
|
42
|
|
|
|
43
|
|
|
@dataclass |
44
|
|
|
class _MoP_base: |
45
|
|
|
legislature: int |
46
|
|
|
state: str # this would be "NRW", "BY", ... |
47
|
|
|
|
48
|
|
|
|
49
|
|
|
@dataclass |
50
|
|
|
class MoP(_MoP_default, Politician, _MoP_base, AttrDisplay): |
51
|
|
|
def __post_init__(self): |
52
|
|
|
if int(self.legislature) not in range(14, 18): |
53
|
|
|
raise NotInRange("Number for legislature not in range") |
54
|
|
|
else: |
55
|
|
|
self.membership.add(self.legislature) |
56
|
|
|
Politician.__post_init__(self) |
57
|
|
|
|
58
|
|
|
|
59
|
|
|
if __name__ == "__main__": |
60
|
|
|
|
61
|
|
|
mop = MoP( |
62
|
|
|
14, |
63
|
|
|
"NRW", |
64
|
|
|
"Tom", |
65
|
|
|
"Schwadronius", |
66
|
|
|
"SPD", |
67
|
|
|
party_entry="1990", # type: ignore |
68
|
|
|
peer_title="Junker von", |
69
|
|
|
born="1950", |
70
|
|
|
) |
71
|
|
|
print(mop) |
72
|
|
|
|
73
|
|
|
mop.add_Party("Grüne", party_entry="30.11.1999") |
74
|
|
|
mop.change_ward("Düsseldorf II") |
75
|
|
|
print(mop) |
76
|
|
|
|