variants.py 9.13 KB
Newer Older
1
2
3
# coding: utf-8


Nicolas Joyard's avatar
Nicolas Joyard committed
4
5
6
7
8
9
10
11
12
13
14
15
16
17
class DelegationHelper:
    '''
    Helper class for building committees/delegations from rep json data
    given dicts for equivalences and abbreviations
    '''

    def __init__(self, equivs, abbrevs, committees=True):
        self.equivs = equivs
        self.abbrevs = abbrevs
        self.committees = committees

    def __call__(self, data):
        items = []
        start = data['mandat_debut']
18
        end = data.get('mandat_fin', None)
Nicolas Joyard's avatar
Nicolas Joyard committed
19
20
21
22
23
24

        if self.committees:
            gdata = (i['responsabilite'] for i in data['responsabilites'])
        else:
            gdata = ([i['responsabilite'] for i in data['responsabilites']] +
                [j['responsabilite'] for j in data['groupes_parlementaires']])
25

Nicolas Joyard's avatar
Nicolas Joyard committed
26
27
28
        for g in gdata:
            orga = g['organisme']
            role = g['fonction']
29

Nicolas Joyard's avatar
Nicolas Joyard committed
30
31
            if self.committees != orga.lower().startswith('commission'):
                continue
32

Nicolas Joyard's avatar
Nicolas Joyard committed
33
34
35
            if orga in self.equivs:
                orga = self.equivs[orga]

36
            item = {
Nicolas Joyard's avatar
Nicolas Joyard committed
37
38
39
40
                'abbr': self.abbrevs[orga] if orga in self.abbrevs else '',
                'name': orga,
                'role': role,
                'start': start
41
42
43
44
45
46
            }

            if end:
                item['end'] = end

            items.append(item)
Nicolas Joyard's avatar
Nicolas Joyard committed
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62

        return items


def _get_rep_district_name(data):
    num = data.get('num_circo')
    nom = data.get('nom_circo')

    if num == 'nd':
        return nom
    else:
        ordinal = u'ère' if num == 1 else u'ème'
        return '%s (%d%s circonscription)' % (nom, num, ordinal)


_get_sen_committees = DelegationHelper({
63
64
65
66
67
    u"COMMISSION DES AFFAIRES EUROPÉENNES Commission des affaires européennes":
        u"Commission des affaires européennes",
    u"Commission de l'aménagement du territoire et du développement durable":
        (u"Commission du développement durable, des infrastructures, de "
            u"l'équipement et de l'aménagement du territoire")
Nicolas Joyard's avatar
Nicolas Joyard committed
68
}, {
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
    u"Commission de la culture, de l'éducation et de la communication":
        "SenComCult",
    u"Commission des affaires économiques": "SenComEco",
    u"Commission des affaires étrangères, de la défense et des forces armées":
        "SenComDef",
    u"Commission des affaires européennes": "SenComEU",
    u"Commission des affaires sociales": "SenComSoc",
    (u"Commission des finances, du contrôle budgétaire et des comptes "
        u"économiques de la nation"): "SenComFin",
    (u"Commission des lois constitutionnelles, de législation, du suffrage "
        u"universel, du Règlement et d'administration générale"): "SenComLois",
    (u"Commission du développement durable, des infrastructures, de "
        u"l'équipement et de l'aménagement du territoire"): "SenComDevD",
    u"Commission sénatoriale pour le contrôle de l'application des lois":
        "SenComAppL"
Nicolas Joyard's avatar
Nicolas Joyard committed
84
})
85

Nicolas Joyard's avatar
Nicolas Joyard committed
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
_get_an_committees = DelegationHelper({}, {
    (u"Commission chargée de l'application de l'article 26 de la "
        u"constitution"): "AnComImmu",
    u"Commission de la défense nationale et des forces armées": "AnComDef",
    u"Commission des affaires culturelles et de l'éducation": "AnComCult",
    u"Commission des affaires économiques": "AnComEco",
    u"Commission des affaires étrangères": "AnComEtrg",
    u"Commission des affaires européennes": "AnComEU",
    u"Commission des affaires sociales": "AnComSoc",
    (u"Commission des finances, de l'économie générale et du contrôle "
        u"budgétaire"): "AnComFin",
    (u"Commission des lois constitutionnelles, de la législation et de "
        u"l'administration générale de la république"): "AnComLois",
    u"Commission du développement durable et de l'aménagement du territoire":
        "AnComDevD"
})
102

Nicolas Joyard's avatar
Nicolas Joyard committed
103
_get_sen_delegations = DelegationHelper({}, {}, False)
104

Nicolas Joyard's avatar
Nicolas Joyard committed
105
_get_an_delegations = DelegationHelper({}, {}, False)
106
107


108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#
# Variant configuration
# - mail_domain is used to distinguish official vs personal emails
# - off_* fields are used for the official address of meps
# - mandates defines how mandates are created from the rep json
#
# Mandates are defined as follows
# - 'kind' indicates the group kind, a constant string
# - 'chamber' tells whether the group belongs to the chamber
# - 'from', if present, must be a function that takes the rep json and returns
#   an array of dicts; one group will be created from each item in the dict.
#   When 'from' is not present, only one group wil be created using the rep
#   json (IOW, 'from' defaults to lambda repjson: [repjson])
# - 'name', 'abbr', 'role', 'start', 'end' are strings that are interpolated
#   against the rep json or items returned by 'from'.
# - 'name_path', 'abbr_path', etc. can replace 'name', 'abbr'... by specifying
#   a slash-separated dictionnary path where the value is to be found in the
#   rep json or item returned by 'from'
# - 'name_fn', 'abbr_fn', etc. can also replace 'name', 'abbr'... by a
#   function that takes the input item (rep json or item returned by 'from')
#   and returns the value
#
FranceDataVariants = {
    "AN": {
        "chamber": u"Assemblée nationale",
133
        "abbreviation": "AN",
134
        "chamber_url_field": "url_an",
135
136
137
138
139
140
141
        "mail_domain": "@assemblee-nationale.fr",
        "off_city": "Paris",
        "off_street": u"Rue de l'Université",
        "off_number": "126",
        "off_code": "75355",
        "off_name": u"Assemblée nationale",
        "mandates": [
Nicolas Joyard's avatar
Nicolas Joyard committed
142
143
144
145
146
147
            {
                "kind": "chamber",
                "chamber": True,
                "abbr": "AN",
                "name": u"Assemblée nationale",
                "role": u"Député",
148
149
                "start": "%(mandat_debut)s",
                "end": "%(mandat_fin)s"
Nicolas Joyard's avatar
Nicolas Joyard committed
150
            },
151
152
153
154
155
156
            {
                "kind": "group",
                "chamber": True,
                "abbr": "%(groupe_sigle)s",
                "name_path": "groupe/organisme",
                "role_path": "groupe/fonction",
157
158
                "start": "%(mandat_debut)s",
                "end": "%(mandat_fin)s"
159
160
161
162
163
            },
            {
                "kind": "department",
                "abbr": "%(num_deptmt)s",
                "name": "%(nom_circo)s",
164
165
                "start": "%(mandat_debut)s",
                "end": "%(mandat_fin)s"
166
167
168
169
170
            },
            {
                "kind": "district",
                "abbr": "%(num_deptmt)s-%(num_circo)s",
                "name_fn": _get_rep_district_name,
171
172
                "start": "%(mandat_debut)s",
                "end": "%(mandat_fin)s"
173
174
            },
            {
175
                "kind": "committee",
176
                "chamber": True,
Nicolas Joyard's avatar
Nicolas Joyard committed
177
                "from": _get_an_committees,
178
179
180
                "abbr": "%(abbr)s",
                "name": "%(name)s",
                "role": "%(role)s",
181
182
                "start": "%(start)s",
                "end": "%(end)s"
183
184
185
186
187
188
189
190
            },
            {
                "kind": "delegation",
                "chamber": True,
                "from": _get_an_delegations,
                "abbr": "%(abbr)s",
                "name": "%(name)s",
                "role": "%(role)s",
191
192
                "start": "%(start)s",
                "end": "%(end)s"
193
194
195
196
197
198
            }
        ]
    },

    "SEN": {
        "chamber": u"Sénat",
199
        "abbreviation": "SEN",
200
        "chamber_url_field": "url_institution",
201
202
203
204
205
206
207
        "mail_domain": "@senat.fr",
        "off_city": "Paris",
        "off_street": u"Rue de Vaugirard",
        "off_number": "15",
        "off_code": "75291",
        "off_name": u"Palais du Luxembourg",
        "mandates": [
Nicolas Joyard's avatar
Nicolas Joyard committed
208
209
210
211
212
213
            {
                "kind": "chamber",
                "chamber": True,
                "abbr": "SEN",
                "name": u"Sénat",
                "role": u"Sénateur",
214
215
                "start": "%(mandat_debut)s",
                "end": "%(mandat_fin)s"
Nicolas Joyard's avatar
Nicolas Joyard committed
216
            },
217
218
219
220
221
222
            {
                "kind": "group",
                "chamber": True,
                "abbr": "%(groupe_sigle)s",
                "name_path": "groupe/organisme",
                "role_path": "groupe/fonction",
223
224
                "start": "%(mandat_debut)s",
                "end": "%(mandat_fin)s"
225
226
227
228
229
            },
            {
                "kind": "department",
                "abbr": "%(num_deptmt)s",
                "name": "%(nom_circo)s",
230
231
                "start": "%(mandat_debut)s",
                "end": "%(mandat_fin)s"
232
233
234
235
236
            },
            {
                "kind": "district",
                "abbr": "%(num_deptmt)s-%(num_circo)s",
                "name_fn": _get_rep_district_name,
237
238
                "start": "%(mandat_debut)s",
                "end": "%(mandat_fin)s"
239
240
            },
            {
241
                "kind": "committee",
242
                "chamber": True,
Nicolas Joyard's avatar
Nicolas Joyard committed
243
                "from": _get_sen_committees,
244
245
246
                "abbr": "%(abbr)s",
                "name": "%(name)s",
                "role": "%(role)s",
247
248
                "start": "%(start)s",
                "end": "%(end)s"
249
250
251
252
253
254
255
256
            },
            {
                "kind": "delegation",
                "chamber": True,
                "from": _get_sen_delegations,
                "abbr": "%(abbr)s",
                "name": "%(name)s",
                "role": "%(role)s",
257
258
                "start": "%(start)s",
                "end": "%(end)s"
259
260
261
262
            }
        ]
    }
}