44 lines
1.4 KiB
Python
44 lines
1.4 KiB
Python
# encoding: utf-8
|
|
"""
|
|
Tool used to upload representatives from French National Assembly.
|
|
"""
|
|
|
|
import csv
|
|
from datetime import datetime
|
|
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 representatives
|
|
data_source = os.path.join(data_root, "json/organe")
|
|
data_target = os.path.join(target_root, "assemblee_nationale_entities.csv")
|
|
with open(data_target, "w", encoding="utf-8", newline="") as csvfile:
|
|
writer = csv.writer(csvfile, delimiter=",", quotechar='"', quoting=csv.QUOTE_MINIMAL)
|
|
writer.writerow(["type_code", "country_iso2", "name", "code", "picture", "start", "end"])
|
|
|
|
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:
|
|
organe = json.load(file_handler)["organe"]
|
|
type_raw = organe["codeType"]
|
|
name = organe["libelle"]
|
|
code = organe["uid"]
|
|
parent = organe["organeParent"]
|
|
start = organe["viMoDe"].get("dateDebut", organe["viMoDe"].get("dateAgrement", None))
|
|
end = organe["viMoDe"].get("dateFin", None)
|
|
# CSV line
|
|
writer.writerow([
|
|
type_raw,
|
|
"FR",
|
|
name,
|
|
code,
|
|
"",
|
|
start,
|
|
end,
|
|
])
|