37 lines
1.2 KiB
Python
37 lines
1.2 KiB
Python
# 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,
|
|
])
|