-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommunication.jl
More file actions
55 lines (46 loc) · 1.7 KB
/
communication.jl
File metadata and controls
55 lines (46 loc) · 1.7 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using Requests
using URIParser
function get_problem(problem_id,to_communication)
if to_communication
r = get("http://sp2lc.salesio-sp.ac.jp/procon.php"; query = {"probID" => problem_id })
if r.data == "error"
println("server error")
exit()
else
return r.data
end
else
r = get(@sprintf("http://localhost/problem/prob%d",int(problem_id)))
return r.data
end
end
function encodebody(table)
pairs = String[]
for k in keys(table)
v = table[k]
key = URIParser.escape(k)
value = URIParser.escape(string(v))
push!(pairs, key * "=" * value)
end
return join(pairs, "&")
end
function post_answer(answer_string, time, version_string, problem_id,to_communication)
if to_communication
#r = post("http://sp2lc.salesio-sp.ac.jp/procon.php"; query = {"answer_string" => answer_string, "time" => time, "version" => version_string, "probID" => problem_id})
println(encodebody({"answer_string" => answer_string, "time" => time, "version" => version_string, "probID" => problem_id}))
r = post("http://sp2lc.salesio-sp.ac.jp/procon.php"; data=encodebody({"answer_string" => answer_string, "time" => time, "version" => version_string, "probID" => problem_id}))
println(r)
if r.data == "error"
println("server error")
exit()
elseif r.data == "ok"
println("complate")
end
println(r.data)
return r.data
else
r = post("http://localhost/SubmitAnswer"; query = {"playerid" => "1", "problemid" => "00", "answer" => answer_string })
println(r)
return r.text
end
end