variants.py 10.1 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# coding: utf-8

# Equivalences of nat. Assembly committees
_equiv_Com_AN = {
}

# Abbreviations for nat. Assembly committees
_abbr_Com_AN = {
    (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"
}

25
26
27
28
29
30
31
32
# Equivalences of nat. Assembly delegations
_equiv_Deleg_AN = {
}

# Abbreviations for nat. Assembly delegations
_abbr_Deleg_AN = {
}

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
# Equivalences of Senate committees
_equiv_Com_SEN = {
    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")
}

# Abbreviations for Senate committees
_abbr_Com_SEN = {
    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"
}

61
62
63
64
65
66
67
68
# Equivalences of Senate delegations
_equiv_Deleg_SEN = {
}

# Abbreviations for Senate delegations
_abbr_Deleg_SEN = {
}

69

Nicolas Joyard's avatar
Nicolas Joyard committed
70
71
72
def _get_rep_district_name(data):
    num = data.get('num_circo')
    nom = data.get('nom_circo')
73
74
75
76
77
78
79
80

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


Nicolas Joyard's avatar
Nicolas Joyard committed
81
82
def _get_sen_committees(data):
    committees = []
Nicolas Joyard's avatar
Nicolas Joyard committed
83
    start = data['mandat_debut']
84

Nicolas Joyard's avatar
Nicolas Joyard committed
85
    for g in data['responsabilites']:
86
87
88
        orga = g['responsabilite']['organisme']
        role = g['responsabilite']['fonction']

89
        if not orga.lower().startswith('commission'):
90
91
92
93
94
            continue

        if orga in _equiv_Com_SEN:
            orga = _equiv_Com_SEN[orga]

Nicolas Joyard's avatar
Nicolas Joyard committed
95
        committees.append({
96
97
98
99
100
101
            'abbr': _abbr_Com_SEN[orga] if orga in _abbr_Com_SEN else '',
            'name': orga,
            'role': role,
            'start': start
        })

Nicolas Joyard's avatar
Nicolas Joyard committed
102
    return committees
103
104


Nicolas Joyard's avatar
Nicolas Joyard committed
105
def _get_sen_delegations(data):
106
    delegations = []
Nicolas Joyard's avatar
Nicolas Joyard committed
107
    start = data['mandat_debut']
108

Nicolas Joyard's avatar
Nicolas Joyard committed
109
110
    for g in ([i['responsabilite'] for i in data['responsabilites']] +
            [j['responsabilite'] for j in data['groupes_parlementaires']]):
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
        orga = g['organisme']
        role = g['fonction']

        if orga.lower().startswith('commission'):
            continue

        if orga in _equiv_Deleg_SEN:
            orga = _equiv_Deleg_SEN[orga]

        delegations.append({
            'abbr': _abbr_Deleg_SEN[orga] if orga in _abbr_Deleg_SEN else '',
            'name': orga,
            'role': role,
            'start': start
        })

    return delegations


Nicolas Joyard's avatar
Nicolas Joyard committed
130
131
def _get_an_committees(data):
    committees = []
Nicolas Joyard's avatar
Nicolas Joyard committed
132
    start = data['mandat_debut']
133

Nicolas Joyard's avatar
Nicolas Joyard committed
134
    for g in data['responsabilites']:
135
136
137
        orga = g['responsabilite']['organisme']
        role = g['responsabilite']['fonction']

138
        if not orga.lower().startswith('commission'):
139
140
141
142
143
            continue

        if orga in _equiv_Com_AN:
            orga = _equiv_Com_AN[orga]

Nicolas Joyard's avatar
Nicolas Joyard committed
144
        committees.append({
145
146
147
148
149
150
            'abbr': _abbr_Com_AN[orga] if orga in _abbr_Com_AN else '',
            'name': orga,
            'role': role,
            'start': start
        })

Nicolas Joyard's avatar
Nicolas Joyard committed
151
    return committees
152
153


Nicolas Joyard's avatar
Nicolas Joyard committed
154
def _get_an_delegations(data):
155
    delegations = []
Nicolas Joyard's avatar
Nicolas Joyard committed
156
    start = data['mandat_debut']
157

Nicolas Joyard's avatar
Nicolas Joyard committed
158
159
    for g in ([i['responsabilite'] for i in data['responsabilites']] +
            [j['responsabilite'] for j in data['groupes_parlementaires']]):
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
        orga = g['organisme']
        role = g['fonction']

        if orga.lower().startswith('commission'):
            continue

        if orga in _equiv_Deleg_AN:
            orga = _equiv_Deleg_AN[orga]

        delegations.append({
            'abbr': _abbr_Deleg_AN[orga] if orga in _abbr_Deleg_AN else '',
            'name': orga,
            'role': role,
            'start': start
        })

    return delegations


179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
#
# 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",
204
        "abbreviation": "AN",
205
206
207
208
209
210
211
212
        "remote_id_field": "url_an",
        "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
213
214
215
216
217
218
219
220
            {
                "kind": "chamber",
                "chamber": True,
                "abbr": "AN",
                "name": u"Assemblée nationale",
                "role": u"Député",
                "start": "%(mandat_debut)s"
            },
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
            {
                "kind": "group",
                "chamber": True,
                "abbr": "%(groupe_sigle)s",
                "name_path": "groupe/organisme",
                "role_path": "groupe/fonction",
                "start": "%(mandat_debut)s"
            },
            {
                "kind": "department",
                "abbr": "%(num_deptmt)s",
                "name": "%(nom_circo)s",
                "start": "%(mandat_debut)s"
            },
            {
                "kind": "district",
                "abbr": "%(num_deptmt)s-%(num_circo)s",
                "name_fn": _get_rep_district_name,
                "start": "%(mandat_debut)s"
            },
            {
242
                "kind": "committee",
243
                "chamber": True,
Nicolas Joyard's avatar
Nicolas Joyard committed
244
                "from": _get_an_committees,
245
246
247
248
                "abbr": "%(abbr)s",
                "name": "%(name)s",
                "role": "%(role)s",
                "start": "%(start)s"
249
250
251
252
253
254
255
256
257
            },
            {
                "kind": "delegation",
                "chamber": True,
                "from": _get_an_delegations,
                "abbr": "%(abbr)s",
                "name": "%(name)s",
                "role": "%(role)s",
                "start": "%(start)s"
258
259
260
261
262
263
            }
        ]
    },

    "SEN": {
        "chamber": u"Sénat",
264
        "abbreviation": "SEN",
265
266
267
268
269
270
271
272
        "remote_id_field": "url_institution",
        "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
273
274
275
276
277
278
279
280
            {
                "kind": "chamber",
                "chamber": True,
                "abbr": "SEN",
                "name": u"Sénat",
                "role": u"Sénateur",
                "start": "%(mandat_debut)s"
            },
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
            {
                "kind": "group",
                "chamber": True,
                "abbr": "%(groupe_sigle)s",
                "name_path": "groupe/organisme",
                "role_path": "groupe/fonction",
                "start": "%(mandat_debut)s"
            },
            {
                "kind": "department",
                "abbr": "%(num_deptmt)s",
                "name": "%(nom_circo)s",
                "start": "%(mandat_debut)s"
            },
            {
                "kind": "district",
                "abbr": "%(num_deptmt)s-%(num_circo)s",
                "name_fn": _get_rep_district_name,
                "start": "%(mandat_debut)s"
            },
            {
302
                "kind": "committee",
303
                "chamber": True,
Nicolas Joyard's avatar
Nicolas Joyard committed
304
                "from": _get_sen_committees,
305
306
307
308
                "abbr": "%(abbr)s",
                "name": "%(name)s",
                "role": "%(role)s",
                "start": "%(start)s"
309
310
311
312
313
314
315
316
317
            },
            {
                "kind": "delegation",
                "chamber": True,
                "from": _get_sen_delegations,
                "abbr": "%(abbr)s",
                "name": "%(name)s",
                "role": "%(role)s",
                "start": "%(start)s"
318
319
320
321
            }
        ]
    }
}