Esempio n. 1
0
def update_uva_problems():

    url = "https://uhunt.onlinejudge.org/api/p"
    res = requests.get(url)
    data = res.json()

    for p in data:

        if len(Problem.objects.filter(prob_id=p[0])) > 0:
            continue

        new_problem = Problem()
        new_problem.prob_id = p[0]
        new_problem.index = p[1]
        new_problem.name = p[2]
        dacu = p[3]
        wa = p[16]

        if dacu != 0:
            rating = min(3600, max(800, (20 - min(log2(dacu), 20)) * 200))
            new_problem.rating = str(int(rating))
            new_problem.difficulty = rating_to_difficulty(rating)

        new_problem.platform = 'U'
        new_problem.url = "https://onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=" + str(
            p[0])
        new_problem.save()

    url = "https://uhunt.onlinejudge.org/api/cpbook/3"
    res = requests.get(url)
    data = res.json()

    for p in data:
        title1 = p['title']
        for q in p['arr']:
            title2 = q['title']
            for r in q['arr']:
                title3 = r[0]
                for i in range(1, len(r)):
                    prob_num = abs(r[i])
                    tags = [title1, title2, title3]
                    Problem.objects.filter(index=prob_num).update(tags=tags)
Esempio n. 2
0
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