Export JSON files in the data directory
This commit is contained in:
parent
626fc4bfd8
commit
27031f8f03
|
@ -1,2 +1,2 @@
|
||||||
app/__pycache__
|
*/__pycache__
|
||||||
Design.org
|
Design.org
|
||||||
|
|
|
@ -1,6 +1,11 @@
|
||||||
datasets = [
|
datasets = [
|
||||||
"coronavirus-commercants-parisiens-livraison-a-domicile"
|
"coronavirus-commercants-parisiens-livraison-a-domicile",
|
||||||
"deconfinement-pistes-cyclables-temporaires"
|
"deconfinement-pistes-cyclables-temporaires",
|
||||||
"deconfinement-paking-relais-doublement-des-places"
|
"deconfinement-parking-relais-doublement-des-places",
|
||||||
]
|
]
|
||||||
url = "https://opendata.paris.fr/api/v2/catalog/datasets/{}/exports/json?rows=-1&pretty=false&timezone=UTC"
|
url = "https://opendata.paris.fr/api/records/1.0/search/?dataset={}&q=&rows=-1"
|
||||||
|
filenames = {
|
||||||
|
"coronavirus-commercants-parisiens-livraison-a-domicile": "home-delivery",
|
||||||
|
"deconfinement-pistes-cyclables-temporaires": "cycling-paths",
|
||||||
|
"deconfinement-parking-relais-doublement-des-places": "relay-parking",
|
||||||
|
}
|
||||||
|
|
|
@ -1,22 +1,28 @@
|
||||||
from constants import datasets, url
|
from constants import datasets, url
|
||||||
from requests import get
|
from requests import get
|
||||||
from json import dump
|
from constants import datasets, url, filenames
|
||||||
|
from requests import get, codes
|
||||||
|
from json import dump, dumps
|
||||||
|
|
||||||
|
|
||||||
def save_json(data):
|
def save_json(data, filename):
|
||||||
with open("cycling-paths.json", "w") as f:
|
data_dir = "../data/"
|
||||||
|
with open(data_dir + filename + ".json", "w") as f:
|
||||||
dump(data, f, ensure_ascii=False)
|
dump(data, f, ensure_ascii=False)
|
||||||
|
|
||||||
|
|
||||||
def request_dataset(url):
|
def request_dataset(url, filename):
|
||||||
request = get(url)
|
response = get(url)
|
||||||
data = request.json()
|
response.raise_for_status()
|
||||||
save_json(data)
|
data = response.json()
|
||||||
|
save_json(data, filename)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def format_url():
|
||||||
url.format("deconfinement-pistes-cyclables-temporaires")
|
for set in datasets:
|
||||||
|
link = url.format(set)
|
||||||
|
request_dataset(link, filenames[set])
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
format_url()
|
||||||
|
|
Loading…
Reference in New Issue