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
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
datasets = [
|
||||
"coronavirus-commercants-parisiens-livraison-a-domicile"
|
||||
"deconfinement-pistes-cyclables-temporaires"
|
||||
"deconfinement-paking-relais-doublement-des-places"
|
||||
"coronavirus-commercants-parisiens-livraison-a-domicile",
|
||||
"deconfinement-pistes-cyclables-temporaires",
|
||||
"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 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):
|
||||
with open("cycling-paths.json", "w") as f:
|
||||
def save_json(data, filename):
|
||||
data_dir = "../data/"
|
||||
with open(data_dir + filename + ".json", "w") as f:
|
||||
dump(data, f, ensure_ascii=False)
|
||||
|
||||
|
||||
def request_dataset(url):
|
||||
request = get(url)
|
||||
data = request.json()
|
||||
save_json(data)
|
||||
def request_dataset(url, filename):
|
||||
response = get(url)
|
||||
response.raise_for_status()
|
||||
data = response.json()
|
||||
save_json(data, filename)
|
||||
|
||||
|
||||
def main():
|
||||
url.format("deconfinement-pistes-cyclables-temporaires")
|
||||
def format_url():
|
||||
for set in datasets:
|
||||
link = url.format(set)
|
||||
request_dataset(link, filenames[set])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
format_url()
|
||||
|
|
Loading…
Reference in New Issue