variants.py 8.93 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
32
33
34
35
            is_committee = orga.lower().startswith('commission') and not (
                orga.lower().startswith(u'commission spéciale') or
                orga.lower().startswith(u'commission d\'enquête')
            )

            if self.committees != is_committee:
Nicolas Joyard's avatar
Nicolas Joyard committed
36
                continue
37

Nicolas Joyard's avatar
Nicolas Joyard committed
38
39
40
            if orga in self.equivs:
                orga = self.equivs[orga]

41
            item = {
Nicolas Joyard's avatar
Nicolas Joyard committed
42
43
44
45
                'abbr': self.abbrevs[orga] if orga in self.abbrevs else '',
                'name': orga,
                'role': role,
                'start': start
46
47
48
49
50
51
            }

            if end:
                item['end'] = end

            items.append(item)
Nicolas Joyard's avatar
Nicolas Joyard committed
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67

        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({
68
69
70
71
72
    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
73
}, {
74
    u"Commission de la culture, de l'éducation et de la communication":
Nicolas Joyard's avatar
Nicolas Joyard committed
75
76
        "Culture",
    u"Commission des affaires économiques": "Économie",
77
    u"Commission des affaires étrangères, de la défense et des forces armées":
Nicolas Joyard's avatar
Nicolas Joyard committed
78
79
80
        "Défense",
    u"Commission des affaires européennes": "Europe",
    u"Commission des affaires sociales": "Social",
81
    (u"Commission des finances, du contrôle budgétaire et des comptes "
Nicolas Joyard's avatar
Nicolas Joyard committed
82
        u"économiques de la nation"): "Finances",
83
    (u"Commission des lois constitutionnelles, de législation, du suffrage "
Nicolas Joyard's avatar
Nicolas Joyard committed
84
        u"universel, du Règlement et d'administration générale"): "Lois",
Nicolas Joyard's avatar
Nicolas Joyard committed
85
})
86

Nicolas Joyard's avatar
Nicolas Joyard committed
87
_get_an_committees = DelegationHelper({}, {
Nicolas Joyard's avatar
Nicolas Joyard committed
88
89
90
91
92
93
    u"Commission de la défense nationale et des forces armées": "Défense",
    u"Commission des affaires culturelles et de l'éducation": "Culture",
    u"Commission des affaires économiques": "Économie",
    u"Commission des affaires étrangères": "Étranger",
    u"Commission des affaires européennes": "Europe",
    u"Commission des affaires sociales": "Social",
Nicolas Joyard's avatar
Nicolas Joyard committed
94
    (u"Commission des finances, de l'économie générale et du contrôle "
Nicolas Joyard's avatar
Nicolas Joyard committed
95
        u"budgétaire"): "Finances",
Nicolas Joyard's avatar
Nicolas Joyard committed
96
    (u"Commission des lois constitutionnelles, de la législation et de "
Nicolas Joyard's avatar
Nicolas Joyard committed
97
        u"l'administration générale de la république"): "Lois"
Nicolas Joyard's avatar
Nicolas Joyard committed
98
})
99

Nicolas Joyard's avatar
Nicolas Joyard committed
100
_get_sen_delegations = DelegationHelper({}, {}, False)
101

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


105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#
# 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",
130
131
132
133
        "abbreviation": u"AN",
        "chamber_url_field": u"url_an",
        "mail_domain": u"@assemblee-nationale.fr",
        "off_city": u"Paris",
134
        "off_street": u"Rue de l'Université",
135
136
        "off_number": u"126",
        "off_code": u"75355",
137
138
        "off_name": u"Assemblée nationale",
        "mandates": [
Nicolas Joyard's avatar
Nicolas Joyard committed
139
            {
140
                "kind": u"chamber",
Nicolas Joyard's avatar
Nicolas Joyard committed
141
                "chamber": True,
142
                "abbr": u"AN",
Nicolas Joyard's avatar
Nicolas Joyard committed
143
144
                "name": u"Assemblée nationale",
                "role": u"Député",
145
146
                "start": u"%(mandat_debut)s",
                "end": u"%(mandat_fin)s"
Nicolas Joyard's avatar
Nicolas Joyard committed
147
            },
148
            {
149
                "kind": u"group",
150
                "chamber": True,
151
152
153
154
155
                "abbr": u"%(groupe_sigle)s",
                "name_path": u"groupe/organisme",
                "role_path": u"groupe/fonction",
                "start": u"%(mandat_debut)s",
                "end": u"%(mandat_fin)s"
156
157
            },
            {
158
159
160
161
162
                "kind": u"department",
                "abbr": u"%(num_deptmt)s",
                "name": u"%(nom_circo)s",
                "start": u"%(mandat_debut)s",
                "end": u"%(mandat_fin)s"
163
164
            },
            {
165
166
                "kind": u"district",
                "abbr": u"%(num_deptmt)s-%(num_circo)s",
167
                "name_fn": _get_rep_district_name,
168
169
                "start": u"%(mandat_debut)s",
                "end": u"%(mandat_fin)s"
170
171
            },
            {
172
                "kind": u"committee",
173
                "chamber": True,
Nicolas Joyard's avatar
Nicolas Joyard committed
174
                "from": _get_an_committees,
175
176
177
178
179
                "abbr": u"%(abbr)s",
                "name": u"%(name)s",
                "role": u"%(role)s",
                "start": u"%(start)s",
                "end": u"%(end)s"
180
181
            },
            {
182
                "kind": u"delegation",
183
184
                "chamber": True,
                "from": _get_an_delegations,
185
186
187
188
189
                "abbr": u"%(abbr)s",
                "name": u"%(name)s",
                "role": u"%(role)s",
                "start": u"%(start)s",
                "end": u"%(end)s"
190
191
192
193
194
195
            }
        ]
    },

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