Advertisement
PikMike

Untitled

May 20th, 2017
371
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.28 KB | None | 0 0
  1. import urllib.request
  2. import json
  3. import time
  4. import sys
  5.  
  6. a = []
  7. b = []
  8. s = ""
  9. handle = "pikmike"
  10.  
  11. with urllib.request.urlopen("http://codeforces.com/api/user.rating?handle=" + handle) as response:
  12.     html = str(response.read())[2:-1].replace('\\x', '.')
  13.     while ('\\\\"' in html):
  14.         html = html.replace('\\\\"', ".")
  15.     s = html
  16.  
  17. while ("contestId" in s):
  18.     pos = s.index("contestId") + len("contestId") + 2
  19.     s = s[pos:]
  20.     a.append([s[:3], 0])
  21.    
  22.     pos = s.index("rank") + len("rank") + 2
  23.     s = s[pos:]
  24.     a[-1][1] = s[:s.index(',')]
  25.  
  26. res = []
  27.  
  28. for contest in a:
  29.     sys.stderr.write(contest[0] + " " + contest[1] + "\n")
  30.     sys.stderr.flush()
  31.    
  32.     with urllib.request.urlopen("http://codeforces.com/api/contest.standings?contestId=" + contest[0] + "&from=" + contest[1] + "&count=10000&showUnofficial=false") as response:
  33.         html = str(response.read())[2:-1].replace('\\x', '.')
  34.         while ('\\\\"' in html):
  35.             html = html.replace('\\\\"', ".")
  36.         tmp = json.loads(html)["result"]["rows"]
  37.        
  38.         for part in tmp:
  39.             if (part["party"]["members"][0]["handle"] == "PikMike"):
  40.                 res.append([int(part["successfulHackCount"]), int(part["unsuccessfulHackCount"])])
  41.                 break
  42.     time.sleep(0.3)
  43.  
  44. #print(res)
  45. s = 0
  46. t = 0
  47. for i in res:
  48.     s += i[0]
  49.     t += i[1]
  50. print("+" + str(s) + ":-" + str(t))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement