-
Notifications
You must be signed in to change notification settings - Fork 0
/
cf_last_submission.py
65 lines (55 loc) · 1.51 KB
/
cf_last_submission.py
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
56
57
58
59
60
61
62
63
64
65
# codeforces api
import time
import random
import hashlib
import httplib
import requests
import json
class bcolors:
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
User = {
'handle' : 'your handle',
'key' : 'your key',
'secret' : 'your secret'
}
apikey = User['key']
#print apikey
utime = str(int(time.time()))
apiSig = str(random.randint(000000,999999))
method = 'user.status'
handle = User['handle']
#Don't change these
string_1 = method+'?handle='+User['handle']+'&from=1&count=1&apiKey='+apikey+'&time='+utime
hash_string = apiSig+'/'+method+'?apiKey='+apikey+'&count=1&from=1&handle='+User['handle']+'&time='+utime+'#'+User['secret']
m = hashlib.sha512()
m.update(hash_string)
url_string = 'http://codeforces.com/api/'+string_1 +'&apiSig='+apiSig+m.hexdigest()
r = requests.get(url_string)
data = r.json()
js_data = json.dumps(data,indent=4)
status = data["status"]
if status == "FAILED":
print data["comment"]
exit(0)
res = data["result"][0]
info = json.dumps(res,indent = 4)
verdict = res["verdict"]
mem_taken = res["memoryConsumedBytes"]
time_taken = res["timeConsumedMillis"]
print "\nYOUR RESULT: "
print "Verdict: ",
if verdict == "OK":
print bcolors.OKGREEN + "Accepted" + bcolors.ENDC
elif verdict == "WRONG_ANSWER":
print bcolors.WARNING + "Wrong Answer" + bcolors.ENDC
else:
print verdict
print "Time Taken: ",time_taken," ms"
print "Memory Used: ",mem_taken, "bytes"