36 lines
975 B
Python
36 lines
975 B
Python
# encoding: utf-8
|
|
"""
|
|
Tool used to upload representatives from French National Assembly.
|
|
"""
|
|
|
|
import os
|
|
import shutil
|
|
|
|
import requests
|
|
|
|
url = "https://data.assemblee-nationale.fr/static/openData/repository/15/amo/tous_acteurs_mandats_organes_xi_legislature/AMO30_tous_acteurs_tous_mandats_tous_organes_historique.json.zip"
|
|
|
|
# Cleaning old data
|
|
try:
|
|
os.remove("../tmp/assemblee_nationale.zip")
|
|
except FileNotFoundError:
|
|
# No file to remove
|
|
pass
|
|
try:
|
|
shutil.rmtree("../tmp/json")
|
|
except FileNotFoundError:
|
|
# No folder to remove
|
|
pass
|
|
|
|
# Download and extract data
|
|
print("Downloading archive")
|
|
with requests.get(url, stream=True) as result:
|
|
result.raise_for_status()
|
|
with open("../tmp/assemblee_nationale.zip", "wb") as f:
|
|
for chunk in result.iter_content(chunk_size=8192):
|
|
f.write(chunk)
|
|
print("Unpacking archive")
|
|
shutil.unpack_archive("../tmp/assemblee_nationale.zip", "../tmp/")
|
|
|
|
os.remove("../tmp/assemblee_nationale.zip")
|