Riz1Ahmed

CF Country Wise Ranklist.py

Jun 13th, 2020
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import urllib.request,json
  2.  
  3. #only edit those two lines
  4. contestId = "1111"
  5. country = "Jordan"
  6.  
  7.  
  8. link = "http://codeforces.com/api/contest.standings?contestId=" + contestId+ "&showUnofficial=false"
  9. a = []
  10. p = {}
  11. print ("Getting data from the contest")
  12. with urllib.request.urlopen(link) as url:
  13. print ("Fetching data from the contest")
  14. data = json.loads(url.read().decode())
  15. print ("Processing data from the contest")
  16. w = url.read()
  17. for x in data["result"]["rows"]:
  18. for i in x["party"]["members"]:
  19. a.append(i["handle"])
  20. p[i["handle"]] = x["rank"]
  21. r = []
  22. q = []
  23. s = 0
  24. step = 500
  25. e = min(len(a),step)
  26. while s < len(a):
  27. link2 = "http://codeforces.com/api/user.info?handles="+";".join(a[s:e])
  28. with urllib.request.urlopen(link2) as url:
  29. data = json.loads(url.read().decode())
  30. for x in data["result"]:
  31. if "country" in x:
  32. if x["country"] == country:
  33. r.append(x["handle"])
  34. print("Done " + str(e))
  35. s += step
  36. e += step
  37. e = min(len(a),e)
  38. print(" ")
  39. for t in r:
  40. print(str(p[t]) + ". " + t)
Add Comment
Please, Sign In to add comment