diff --git a/venissieux-technocarte/run.py b/venissieux-technocarte/run.py index f6239c2..0549a0a 100644 --- a/venissieux-technocarte/run.py +++ b/venissieux-technocarte/run.py @@ -125,8 +125,24 @@ def create_adultes(args): data['telephone'] = row['NUMTEL'] data['courriel'] = row['MAIL'] data['numero_voie'] = "%s %s" % (row['NUMVOI'], row['ADRENF1']) + numbis = row['NUMBIS'] + if numbis: + numbis = numbis.capitalize() + if numbis in ('Bis', 'Ter', 'Quater'): + data['bis'] = numbis data['code_postal'] = row['CODPOSENF'] data['commune'] = row['COMMUNE'] + if row['NUMTEL2']: + data['portable'] = row['NUMTEL2'] + civilite = row['FORPOL'] + civilite_clean = None + if civilite == 'M.': + civilite_clean = 'Monsieur' + elif civilite == 'Mme': + civilite_clean = 'Madame' + if civilite_clean: + data['civilite'] = civilite_clean + resp = wcs_api_call(url, args, data) familles_adulte_count[code_famille] += 1 @@ -142,30 +158,48 @@ def create_adultes(args): def create_enfants(args): enfants = {} + familles_enfants = collections.defaultdict(list) url = args.wcs_api_url + 'cards/%s/submit' % CARD_ENFANT_SLUG for row in get_rows(args): if row['ADULTE'] == '1': continue data = init_human_data(row) + + if row['ZONSCOL']: + data['zone_scolaire'] = row['ZONSCOL'] + if row['ECOLE']: + data['ecole'] = row['ECOLE'] + if row['INSCRITSCO']: + data['date_premiere_inscription'] = time.strftime( + '%Y-%m-%d', + time.strptime(row['INSCRITSCO'][:10], '%d/%m/%Y') + ) + if row['GRPSCO']: + data['groupe_scolaire'] = row['GRPSCO'] + resp = wcs_api_call(url, args, data) + technocarte_famille_id = row['CODFAM'] enfant = { 'technocarte_id': row['CODENF'], 'publik_id': str(resp.json()['data']['id']), - 'technocarte_famille_id': row['CODFAM'] + 'technocarte_famille_id': technocarte_famille_id } if row['CODPEREBIO']: enfant['pere_technocarte_id'] = row['CODPEREBIO'] if row['CODMEREBIO']: enfant['mere_technocarte_id'] = row['CODMEREBIO'] + if row['CAF']: + enfant['numero_allocataire_caf'] = row['CAF'] enfants[row['CODENF']] = enfant + familles_enfants['technocarte_famille_id'].append(enfant) - return enfants + return enfants, familles_enfants -def create_familles(adultes, enfants, args): +def create_familles(adultes, familles_enfants, args): familles_map = {} url = args.wcs_api_url + 'cards/%s/submit' % CARD_FAMILLE_SLUG for adulte_technocarte_id, adulte in adultes.items(): @@ -176,6 +210,15 @@ def create_familles(adultes, enfants, args): 'famille': adulte['nom'], 'adulte1': adulte['publik_id'] } + # try to grab a numero_allocataire_caf + numero_allocataire_caf = None + for enfant in familles_enfants.get(technocarte_famille_id, []): + numero_allocataire_caf = enfant.get('numero_allocataire_caf') + if numero_allocataire_caf: + break + if numero_allocataire_caf: + data['numero_allocataire_caf'] = numero_allocataire_caf + url = args.wcs_api_url + 'cards/%s/submit' % CARD_FAMILLE_SLUG resp = wcs_api_call(url, args, data) familles_map[technocarte_famille_id] = str(resp.json()['data']['id']) @@ -221,8 +264,8 @@ def create_gardes(enfants, familles, args): def import_data(args): adultes = create_adultes(args) - enfants = create_enfants(args) - familles = create_familles(adultes, enfants, args) + enfants, familles_enfants = create_enfants(args) + familles = create_familles(adultes, familles_enfants, args) create_gardes(enfants, familles, args)