37 lines
1.1 KiB
Python
37 lines
1.1 KiB
Python
# encoding: utf-8
|
|
"""
|
|
Tool used to upload representatives from French National Assembly.
|
|
"""
|
|
|
|
import csv
|
|
import json
|
|
import os
|
|
import sys
|
|
|
|
# Extract roles
|
|
print("Scraping roles")
|
|
with open("../tmp/assemblee_nationale_roles.csv", "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("../tmp/json/acteur"):
|
|
print(".", end="")
|
|
sys.stdout.flush()
|
|
# Loading informations
|
|
with open(os.path.join("../tmp/json/acteur", 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,
|
|
])
|