-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbenefit.py
92 lines (76 loc) · 2.93 KB
/
benefit.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
from typing import List
class BenefitCondition():
type = str
values = list
operator = str
def __init__(self, dict: dict) -> None:
self.type = dict.get('type', '')
self.values = dict.get('values', [])
self.operator = dict.get('operator', '')
class BenefitProfile():
type: str
conditions: List[BenefitCondition]
def __init__(self, dict: dict) -> None:
self.type = dict.get('type', '')
self.conditions = [BenefitCondition(
condition) for condition in dict.get('conditions', [])]
def get_conditions_type(self) -> List[str]:
return [condition.type for condition in self.conditions]
class Benefit():
"""
Apparently bad idea to use this.
We need to make missing fields crash.
Refacto by removing the `dict.get()` method might be worth
"""
label = str
institution = str
description = str
prefix = str
conditions_generales: list
profils: List[BenefitProfile]
conditions: List[BenefitCondition]
interestFlag: str
type: str
unit: str
periodicite: str
montant: int
link: str
instructions: str
teleservice: str
periodicite: str
legend: str
file_path = str
def __init__(self, dict: dict) -> None:
try:
self.label = dict.get('label', '')
self.institution = dict.get('institution', '')
self.description = dict.get('description', '')
self.prefix = dict.get('prefix', '')
self.conditions_generales = [BenefitCondition(
condition) for condition in dict.get('conditions_generales', [])]
self.profils = [BenefitProfile(profil)
for profil in dict.get('profils', [])]
self.conditions = dict.get('conditions', [''])
self.interestFlag = dict.get('interestFlag', '')
self.type = dict.get('type', '')
self.unit = dict.get('unit', '')
self.periodicite = dict.get('periodicite', '')
self.montant = dict.get('montant', None)
self.link = dict.get('link', '')
self.instructions = dict.get('instructions', '')
self.teleservice = dict.get('teleservice', '')
self.periodicite = dict.get('periodicite', '')
self.legend = dict.get('legend', '')
self.file_path = dict.get('file_path', '')
except KeyError:
raise KeyError
def get_profils_types(self) -> list:
return [profil.type for profil in self.profils]
def get_all_conditions_types(self) -> list:
conditions = [
condition.type for condition in self.conditions_generales]
profils_conditions = [
condition for profil in self.profils for condition in profil.get_conditions_type()]
return conditions + profils_conditions
def get_label_and_institution(self) -> str:
return f'{self.label} => {self.institution}'