update,
This commit is contained in:
36
vihuwach/task1/archive/task1.py
Normal file
36
vihuwach/task1/archive/task1.py
Normal file
@@ -0,0 +1,36 @@
|
||||
# https://api.data.gov.hk/v1/carpark-info-vacancy?data=vacancy&vehicleTypes=privateCar
|
||||
import requests
|
||||
from pprint import pprint
|
||||
import json
|
||||
|
||||
url = "https://api.data.gov.hk/v1/carpark-info-vacancy"
|
||||
params = {
|
||||
"data": "vacancy",
|
||||
"vehicleTypes": "privateCar"
|
||||
}
|
||||
|
||||
response = requests.get(url, params=params)
|
||||
js_result_vacancy = response.json()['results']
|
||||
|
||||
url = "https://api.data.gov.hk/v1/carpark-info-vacancy"
|
||||
|
||||
response = requests.get(url)
|
||||
js_result_all = response.json()['results']
|
||||
|
||||
output = []
|
||||
for jrv in js_result_vacancy:
|
||||
for jra in js_result_all:
|
||||
if jrv['park_Id'] == jra['park_Id']:
|
||||
output.append(jra)
|
||||
break
|
||||
|
||||
js_row = output[0]
|
||||
|
||||
pprint(js_row)
|
||||
pprint("length of json: "+str(len(output)))
|
||||
|
||||
# Store js_result into js_result.json
|
||||
with open('js_result_o.json', 'w') as outfile:
|
||||
json.dump(output, outfile, indent=2)
|
||||
|
||||
task1_json = output
|
Reference in New Issue
Block a user