-
Notifications
You must be signed in to change notification settings - Fork 0
/
pollution_rpc.jl
39 lines (35 loc) · 1.06 KB
/
pollution_rpc.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
using HTTP
using JSON3
# windows powershell:
# curl.exe -X GET 'http://localhost:9000/query2json' -d '[\"ancona\",\"o3\",150]'
function value(response)
content = JSON3.read(response.body, Any)
reason = "invalid response $content"
if haskey(content, "status")
if content["status"] == 0
try
return JSON3.read(content["value"], Any)
catch e
# if not a valid JSON return the string
return content["value"]
end
elseif haskey(content, "value") && content["value"] !== nothing
reason = content["value"]
else
reason = "code: $(content["status"])"
end
end
error("error: $reason")
end
function create(city)
res = HTTP.get(
"http://127.0.0.1:9000/create", [], JSON3.write([city])
)
return value(res)
end
function query(city, element, thr)
res = HTTP.get(
"http://127.0.0.1:9000/query2json", [], JSON3.write([city, element, thr])
)
return value(res)
end