Ejemplo n.º 1
0
def contestCommand(data):
    session = requests.Session()
    command = data.get('contest_command')

    if command == 'get':
        read = readContest(data.get('contest'), session)
        getCommand({
            **data,
            'command': 'get',
            'problem': read.get('problems'),
        })
Ejemplo n.º 2
0
def contestCommand(data):
    session = requests.Session()
    command = data.get('contest_command')

    if command == 'get':
        contestData = readContest(data.get('contest'), session)
        if not contestData.get('inProgress'):
            timeTo = contestData.get('timeTo')
            if timeTo and timeTo.total_seconds() > 0:
                print('Contest is not in progress.')
                print(f'Contest begins in {timeTo}.')
                return
            else:
                print('The contest seems to be over.')
                if len(contestData.get('problems')) > 0:
                    print(
                        'Do you want to get the problems from the contest anyways?'
                    )
                    if not yes():
                        return
        solved = getCommand({
            **data,
            'command': 'get',
            'problem': contestData.get('problems'),
        })
        if solved:
            if not data.get('submit'):
                print("Some problems were unarchived from the .solved folder:")
                print(", ".join(solved))
                print("Do you want to submit them?")
                if not yes():
                    return
            for problem in solved:
                submitCommand({"problem": problem})
Ejemplo n.º 3
0
def contestCommand(data):
    session = requests.Session()
    contest = data.get('contest-id')
    contestData = readContest(contest, session)
    if contestData.get('timeState') == TimeState.NotStarted:
        timeTo = contestData.get('timeTo')
        print('Contest has not started yet.')
        print(f'Contest begins in {timeTo}.')
        print("Do you want to run this command again when the contest starts?")
        if not yes():
            return
        print("Waiting for contest to start...")
        while contestData.get('timeState') == TimeState.NotStarted:
            timeTo = contestData.get('timeTo')
            timeToInSeconds = timeTo.total_seconds() if timeTo is not None else -1 # the -1 denotes that we don't know how long it is to contest start, and will result in the code checking every second
            if timeToInSeconds > 10:
                time.sleep(timeToInSeconds - 10)
            else:
                time.sleep(1)
            contestData = readContest(contest, session)


    elif contestData.get('timeState') == TimeState.Ended:
        print('The contest seems to be over.')
        if len(contestData.get('problems')) > 0:
            print('Do you want to get the problems from the contest anyways?')
            if not yes():
                return
    solved = getCommand({
        **data,
        'command': 'get',
        'problem': contestData.get('problems'),
        'language': None,
    })
    #update config with new problems
    config = getConfig()
    config['contest'] = contestData['problemMap']
    saveConfig()


    if solved:
        if not data.get('submit'):
            print("Some problems were unarchived from the .solved folder:")
            print(", ".join(solved))
            print("Do you want to submit them?")
            if not yes():
                return
        for problem in solved:
            submitCommand({"problem": problem, "force": True, "archive": True})
Ejemplo n.º 4
0
def getProblem(currentIndex, data, problems):
    currentProblem = problems[currentIndex]

    getCommand({**data, 'problem': [currentProblem]})

    return currentProblem