tools/assemblee_nationale/scrap_entities.py

37 lines
1.2 KiB
Python
Raw Normal View History

2021-07-23 17:21:38 +02:00
# encoding: utf-8
"""
Tool used to upload representatives from French National Assembly.
"""
import csv
from datetime import datetime
import json
import os
# Extract representatives
print("Scraping entities")
with open("../tmp/assemblee_nationale_entities.csv", "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("../tmp/json/organe"):
# Loading informations
with open(os.path.join("../tmp/json/organe", 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,
])