tools/assemblee_nationale/scrap_types.py

71 lines
2.5 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# encoding: utf-8
"""
Tool used to upload representatives from French National Assembly.
"""
import csv
import json
import os
import sys
TYPES = {
"API": "Assemblée parlementaire internationale",
"ASSEMBLEE": "Assemblée Nationale",
"CJR": "Cour de Justice de la République",
"CMP": "Commission mixte paritaire",
"CNPE": "Commission denquête",
"CNPS": "Commission spéciale",
"COMNL": "Autre commission permanente",
"COMPER": "Commission permanente législative",
"COMSENAT": "Commission sénatoriale",
"COMSPSENAT": "Commission spéciale sénatoriale",
"CONFPT": "Conférence des Présidents",
"CONSTITU": "Conseil constitutionnel",
"DELEG": "Délégation parlementaire",
"DELEGBUREAU": "Délégation du Bureau de l'Assemblée Nationale",
"DELEGSENAT": "Délégation sénatoriale",
"GA": "Groupe d'amitié",
"GE": "Groupe d'études",
"GEVI": "Groupe détudes à vocation internationale",
"GOUVERNEMENT": "Gouvernement",
"GP": "Groupe politique",
"GROUPESENAT": "Groupe sénatorial",
"HCJ": "Haut Cour de Justice",
"MINISTERE": "Ministère",
"MISINFO": "Mission dinformation",
"MISINFOCOM": "Mission dinformation commune",
"MISINFOPRE": "Missions dinformation de la conférence des Présidents",
"OFFPAR": "Office parlementaire ou délégation mixte",
"ORGEXTPARL": "Organisme extra parlementaire",
"PARPOL": "Parti politique",
"PRESREP": "Présidence de la République",
"SENAT": "Sénat",
}
data_root = os.environ.get("POLITIKORAMA_DATA_ROOT", "../tmp")
target_root = os.path.join(data_root, "assemblee_nationale")
# Extract types
data_source = os.path.join(data_root, "json/organe")
data_target = os.path.join(target_root, "assemblee_nationale_types.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"])
types = {}
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"]
if organe["codeType"].upper() not in types:
types[organe["codeType"].upper()] = TYPES.get(organe["codeType"].upper(), organe["codeType"].upper())
for type_code in types:
# CSV line
writer.writerow([
type_code,
types[type_code],
])