Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # CODEFORCES =====================================================
- apiKey = "..."
- apiSecret = "..."
- count_response = 0
- def get_cf_response(url):
- global count_response
- if count_response==5:
- count_response = 0
- time.sleep(2)
- r = requests.get(url)
- count_response += 1
- return r.json()
- def get_codeforces_contest_stadings(contestId, showUnofficial=False):
- if showUnofficial:
- showUnofficial = 'true'
- else:
- showUnofficial = 'false'
- t = int(time.time())
- s = bytes("rororo/contest.standings?
- apiKey="+apiKey+"&contestId="+str(contestId)+"&showUnofficial="+showUnofficial+"&time="+str(t)+"#"+apiSecret, 'utf-8')
- h = hashlib.sha512(s).hexdigest()
- url = "http://codeforces.com/api/contest.standings?
- contestId="+str(contestId)+"&showUnofficial="+showUnofficial+"&apiKey="+apiKey+"&time="+str(t)+"&apiSig=rororo"+h
- #print(url)
- return get_cf_response(url)
- def get_contestName(contestId):
- try:
- standings = get_codeforces_contest_stadings(contestId)
- return standings['result']['contest']['name']
- except:
- return None
- # [ {'handle': "", 'points': []} ... ]
- def get_standings(contestId, showUnofficial=False):
- standings = get_codeforces_contest_stadings(contestId, showUnofficial)
- try:
- ans = []
- for x in standings['result']['rows']:
- handle = x['party']['members'][0]['handle']
- current_user = {'handle': handle, 'points': []}
- for problem in x['problemResults']:
- points = problem['points']
- current_user['points'].append(points)
- flag = False
- for i in range(len(ans)):
- if ans[i]['handle'] == current_user['handle']:
- flag = True
- for j in range(len(current_user['points'])):
- ans[i]['points'][j] = max(ans[i]['points'][j], current_user['points'][j])
- if flag == False:
- ans.append(current_user)
- return ans
- except:
- return None
- # ============================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement