if "<b>" in text: a = text.split(' <b>') record[2] = a[0] record[3] = a[1] else: record[2] = clean(text) record[2] = clean_app(record[2]).replace("Rassemblement-", "R").replace("ÉCOL.", 'ECOLO').replace('Ecolo', 'ECOLO') else: record[3] = clean(text) if record[3]: if not "".join(record[:2]): tmp = clean(record[3]) record = results.pop() record[3] = "%s %s" % (clean(record[3]), tmp) record[3] = unif_partis(record[3]) parl = find_parl(record[0], record[1], record[2], parls) if parl: if record[3] == "Aucun rattachement": record[3] = "Non rattaché" if parl['sexe'] == 'F': record[3] += "e" record[4] = parl.get('sexe').encode('utf-8') record[5] = parl.get('nom_circo').encode('utf-8') record[6] = parl.get('slug').encode('utf-8') record[7] = parl.get('url_institution', parl.get('url_an')).encode('utf-8') results.append(record) record = ["", "", "", "", "", "", "", ""] if not drawMap: print ",".join(['"%s"' % h for h in headers]) for i in results:
filepath = sys.argv[1] with open(filepath, 'r') as csv_file: csv = list(csv.DictReader(csv_file, delimiter=";")) results = [] headers = ['nom', 'prénom', 'groupe', 'rattachement_parti', 'sexe', 'département', 'id_nosdeputes', 'url_institution'] record = ["", "", "", "", "", "", "", ""] with open("cache/deputes.json") as f: parls = [p["depute"] for p in json.load(f)['deputes']] for line in csv: for k in line: line[k] = line[k].decode('iso-8859-15').encode('utf-8') groupe = line["Groupe"].replace("app.", "").replace("Écolo", "ECOLO") parl = find_parl(line['Nom'], line['Pr\xe9nom'], groupe, parls) if not parl: print >> sys.stderr, "WARNING: could not process", line continue results.append([ line['Nom'], line['Pr\xe9nom'], line['Groupe'], unif_partis(line['Parti ou groupement politique']), parl['sexe'], parl['nom_circo'], parl['slug'], parl['url_an'] ]) print ",".join(['"%s"' % h for h in headers])
circos[circo].append(line) circosparls = {} for parl in parls: try: circo = "%03d%02d" % (int(parl['num_deptmt']), int(parl['num_circo'])) except: circo = "%s%02d" % (parl['num_deptmt'].upper(), int(parl['num_circo'])) if circo not in circosparls: circosparls[circo] = [] circosparls[circo].append(parl) for circo, candidats in circos.items(): parl = None for line in candidats: parl = find_parl(line['Nom candidat'], line['Prénom candidat'], None, circosparls[circo], silent=True) if parl: break if not parl: print >> sys.stderr, "WARNING: could not find député", ["%s | %s" % (checker(p["nom"]), p["groupe_sigle"]) for p in circosparls[circo]], "for circo", circo pprint(["%s | %s" % (checker("%s %s" % (p['Prénom candidat'], p['Nom candidat'])), p['Parti rattachement'].decode("utf-8")) for p in candidats], stream=sys.stderr) print >> sys.stderr parl = circosparls[circo][0] line['Nom candidat'] = parl["nom_de_famille"].upper() line['Prénom candidat'] = parl["prenom"] line['Parti rattachement'] = "Non rattaché%s" % ("e" if parl["sexe"] == "F" else "") results.append([ line['Nom candidat'], line['Prénom candidat'], parl['groupe_sigle'],
filepath = sys.argv[1] with open(filepath, 'r') as csv_file: csv = list(csv.DictReader(csv_file, delimiter=";")) results = [] headers = ['nom', 'prénom', 'groupe', 'rattachement_parti', 'sexe', 'département', 'id_nosdeputes', 'url_institution'] record = ["", "", "", "", "", "", "", ""] with open("cache/deputes.json") as f: parls = [p["depute"] for p in json.load(f)['deputes']] for line in csv: for k in line: line[k] = (line[k] or "").decode('iso-8859-15').encode('utf-8') groupe = line["Groupe"].replace("app.", "").replace("Écolo", "ECOLO") parl = find_parl(line['Nom'], line.get('Pr\xe9nom', ''), groupe, parls) if not parl: print >> sys.stderr, "WARNING: could not process", line continue if "-2019" in filepath and not line['Parti ou groupement politique']: line['Parti ou groupement politique'] = line['Groupe'] line['Groupe'] = "" results.append([ line['Nom'], line.get('Pr\xe9nom', parl['prenom']), line['Groupe'], unif_partis(line['Parti ou groupement politique']), parl['sexe'], parl['nom_circo'], parl['slug'], parl['url_an']