def update_atcoder_problems(): url = "https://kenkoooo.com/atcoder/resources/contests.json" res = requests.get(url) data = res.json() for contest in data: if len(atcoder_contest.objects.filter(contestId=contest['id'])) == 0: new_contest = atcoder_contest() new_contest.name = contest['title'] new_contest.contestId = contest['id'] new_contest.startTime = contest['start_epoch_second'] new_contest.duration = contest['duration_second'] new_contest.save() url = "https://kenkoooo.com/atcoder/resources/problems.json" res = requests.get(url) data = res.json() for prob in data: if len(Problem.objects.filter(prob_id=prob['id'], platform='A')) == 0: new_problem = Problem() new_problem.prob_id = prob['id'] new_problem.contest_id = prob['contest_id'] new_problem.name = prob['title'] new_problem.url = "https://atcoder.jp/contests/" + prob[ 'contest_id'] + "/tasks/" + prob['id'] new_problem.index = prob['id'].split("_")[-1] new_problem.platform = 'A' new_problem.save() url = "https://kenkoooo.com/atcoder/resources/problem-models.json" res = requests.get(url) data = res.json() problems = Problem.objects.filter(difficulty=None, platform='A') for prob in problems: if prob.prob_id in data: if 'difficulty' in data[prob.prob_id]: old = data[prob.prob_id]['difficulty'] if old < -1000: NewValue = (((old + 10000) * 50) / 9000) + 800 elif old <= 0: NewValue = (((old + 1000) * 350) / 1000) + 850 else: NewValue = ((old * 2400) / 5000) + 1200 prob.rating = str(int(NewValue)) prob.difficulty = rating_to_difficulty(int(NewValue)) prob.save()
def codeforces_update_problems(): # check whether we have updated the problems of a particular contest , # if no , update the problems , else not .. url = "https://codeforces.com/api/contest.list" res = requests.get(url) data = res.json() if (data["status"] != 'OK'): return for codeforces_contest in data['result']: url = "https://codeforces.com/api/contest.standings?contestId=" + str( codeforces_contest['id']) + "&from=1&count=1" res = requests.get(url) data = res.json() if (data["status"] != 'OK'): continue new_contest = contest() if 'startTimeSeconds' in codeforces_contest: new_contest.startTime = codeforces_contest['startTimeSeconds'] new_contest.Type = 'R' new_contest.contestId = codeforces_contest['id'] new_contest.name = codeforces_contest['name'] new_contest.duration = codeforces_contest['durationSeconds'] if len(contest.objects.filter( contestId=codeforces_contest['id'])) == 0: new_contest.save() for contest_problem in data['result']['problems']: new_problem = Problem() new_problem.name = contest_problem['name'] new_problem.contest_id = contest_problem['contestId'] new_problem.prob_id = str( contest_problem['contestId']) + contest_problem['index'] new_problem.url = "https://codeforces.com/contest/" + str( contest_problem['contestId'] ) + "/problem/" + contest_problem['index'] new_problem.platform = 'F' new_problem.index = contest_problem['index'] new_problem.tags = contest_problem['tags'] if 'rating' in contest_problem: new_problem.rating = contest_problem['rating'] new_problem.difficulty = rating_to_difficulty( int(contest_problem['rating'])) if len( Problem.objects.filter( prob_id=str(contest_problem['contestId']) + contest_problem['index'])) == 0: new_problem.save() url = "https://codeforces.com/api/contest.list?gym=true" res = requests.get(url) data = res.json() if (data["status"] != 'OK'): return for codeforces_contest in data['result']: url = "https://codeforces.com/api/contest.standings?contestId=" + str( codeforces_contest['id']) + "&from=1&count=1" res = requests.get(url) data = res.json() if (data["status"] != 'OK'): continue new_contest = contest() if 'startTimeSeconds' in codeforces_contest: new_contest.startTime = codeforces_contest['startTimeSeconds'] new_contest.Type = 'R' new_contest.contestId = codeforces_contest['id'] new_contest.name = codeforces_contest['name'] new_contest.duration = codeforces_contest['durationSeconds'] if len(contest.objects.filter( contestId=codeforces_contest['id'])) == 0: new_contest.save() for contest_problem in data['result']['problems']: new_problem = Problem() new_problem.name = contest_problem['name'] new_problem.contest_id = contest_problem['contestId'] new_problem.prob_id = str( contest_problem['contestId']) + contest_problem['index'] new_problem.url = "https://codeforces.com/gym/" + str( contest_problem['contestId'] ) + "/problem/" + contest_problem['index'] new_problem.platform = 'F' new_problem.index = contest_problem['index'] new_problem.tags = contest_problem['tags'] if 'rating' in contest_problem: new_problem.rating = contest_problem['rating'] new_problem.difficulty = rating_to_difficulty( int(contest_problem['rating'])) if len( Problem.objects.filter( prob_id=str(contest_problem['contestId']) + contest_problem['index'])) == 0: new_problem.save() return