venissieux-technocarte: take the first two adults for a given family (#54356)

This commit is contained in:
Emmanuel Cazenave 2021-05-31 16:52:28 +02:00
parent 36aa1d99da
commit b9b15e688c
1 changed files with 17 additions and 5 deletions

View File

@ -1,4 +1,5 @@
import base64
import collections
import csv
import datetime
@ -114,11 +115,18 @@ def init_human_data(row):
def create_adultes():
adultes = {}
familles_adulte_count = collections.defaultdict(int)
url = WCS_BASE_URL + 'cards/adultes/submit'
for row in get_rows():
if row['ADULTE'] != '1':
continue
code_famille = row['CODFAM']
if familles_adulte_count[code_famille] >= 2:
# gestion des doublons
continue
data = init_human_data(row)
data['telephone'] = row['NUMTEL']
data['courriel'] = row['MAIL']
@ -127,10 +135,11 @@ def create_adultes():
data['commune'] = row['COMMUNE']
resp = api_call(url, data)
familles_adulte_count[code_famille] += 1
adultes[row['CODENF']] = {
'technocarte_id': row['CODENF'],
'publik_id': str(resp.json()['data']['id']),
'technocarte_famille_id': row['CODFAM'],
'technocarte_famille_id': code_famille,
'nom': row['NOMENF']
}
@ -177,17 +186,20 @@ def create_familles(adultes, enfants):
resp = api_call(url, data)
familles_map[technocarte_famille_id] = str(resp.json()['data']['id'])
else:
# ajouter comme deuxième adulte à la famille existante
url = WCS_BASE_URL + 'cards/%s/%s/' % (
CARD_FAMILLE_SLUG, familles_map[technocarte_famille_id]
)
card = api_call(url, method='get').json()
if card['fields']['adulte2']:
# gestion des doublons, s'il ya déjà un deuxième adulte, on zappe
continue
# ajouter comme deuxième adulte à la famille existante
data = {
'adulte2': adulte['publik_id']
}
nom_famille = api_call(url, method='get').json()['fields']['famille']
if nom_famille != adulte['nom']:
if card['fields']['famille'] != adulte['nom']:
# les gens ne se marient plus
data['famille'] = "%s %s" % (nom_famille, adulte['nom'])
data['famille'] = "%s %s" % (card['fields']['famille'], adulte['nom'])
api_call(url, data)