41 lines
1.3 KiB
Python
41 lines
1.3 KiB
Python
# encoding: utf-8
|
|
"""
|
|
Tool used to upload representatives from French National Assembly.
|
|
"""
|
|
|
|
import csv
|
|
import json
|
|
import os
|
|
import sys
|
|
|
|
data_root = os.environ.get("POLITIKORAMA_DATA_ROOT", "../tmp")
|
|
target_root = os.path.join(data_root, "assemblee_nationale")
|
|
|
|
# Extract roles
|
|
data_source = os.path.join(data_root, "json/acteur")
|
|
data_target = os.path.join(target_root, "assemblee_nationale_roles.csv")
|
|
with open(data_target, "w", encoding="utf-8", newline="") as csvfile:
|
|
writer = csv.writer(csvfile, delimiter=",", quotechar='"', quoting=csv.QUOTE_MINIMAL)
|
|
writer.writerow(["code", "name"])
|
|
|
|
roles = []
|
|
for filename in os.listdir(data_source):
|
|
print(".", end="")
|
|
sys.stdout.flush()
|
|
# Loading informations
|
|
with open(os.path.join(data_source, filename)) as file_handler:
|
|
acteur = json.load(file_handler)["acteur"]
|
|
mandats = acteur["mandats"]["mandat"]
|
|
if isinstance(mandats, dict):
|
|
mandats = [mandats]
|
|
for mandat in mandats:
|
|
role = mandat["infosQualite"].get("codeQualite", "")
|
|
if role not in roles and role is not None:
|
|
roles.append(role)
|
|
for role in roles:
|
|
# CSV line
|
|
writer.writerow([
|
|
role,
|
|
role,
|
|
])
|