Ryuuk

Codeforces_API

Dec 28th, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.72 KB | None | 0 0
  1. #python 3
  2. import time
  3. import hashlib
  4. import random,json
  5. #pip install requests
  6. import requests
  7.  
  8. #function to get current time in unix format
  9. current_milli_time = lambda: int(round(time.time() * 1000))
  10.  
  11. apikey="xxxxxxxxxx"
  12. secret="xxxxxxxxxx"
  13.  
  14. curTime=current_milli_time()
  15. rand = random.randint(100000,900000)
  16. api="http://codeforces.com/api/"
  17. method="contest.standings?"
  18. contestId="566"
  19. hash="%s/%sapiKey=%s&contestId=%s&time=%s#%s"%(rand, method, apikey, contestId, curTime, secret)
  20. hash=hashlib.sha512(("%s"%(hash)).encode('utf-8')).hexdigest()
  21. arg="contestId=%s&apiKey=%s&time=%s&apiSig=%s%s"%(contestId, apikey, curTime, rand, hash)
  22. #print (api+method+arg)
  23. req= requests.get(api+method+arg)
  24. print(req.json())
Add Comment
Please, Sign In to add comment