Esempio n. 1
0
def collectProblems(data):
    session = requests.Session()
    url = getConfigUrl("problemsurl", "problems")
    parameters = buildParameters(data)
    login(session)
    problems = fetchProblems(url, parameters, data, session)
    return problems
Esempio n. 2
0
def printUntilDone(id, problemName, config, session, options):
    lastCount = 0

    print("โš–๏ธ  Submission Status:")

    while True:
        login(config, session)
        response, testCount, testTotal = fetchNewSubmissionStatus(
            id, session, config, options)
        if response != Response.Success:
            return response
        for i in range(0, abs(lastCount - testCount)):
            sys.stdout.write("๐Ÿ’š")
        sys.stdout.flush()

        if testTotal != 0 and testCount == testTotal:
            break

        lastCount = testCount
        time.sleep(1)

    print()
    print("๐ŸŽ‰ Congratulations! You completed all " + str(testTotal) +
          " tests for " + problemName)
    return Response.Success
Esempio n. 3
0
File: list.py Progetto: hojelse/Kat
def collectProblems(args, options):
    session = requests.Session()
    config = getConfig()
    url = "https://open.kattis.com/problems/"
    parameters = buildParameters(args, options)
    login(config, session)
    problems = fetchProblems(url, parameters, args, session)
    return problems
Esempio n. 4
0
def printUntilDone(id, problemName, session):
    lastCount = 0
    spinnerParts = ["-", "\\", "|", "/"]
    runtime = None

    print("โš–๏ธ  Submission Status:")

    while True:
        login(session)
        response, data = fetchNewSubmissionStatus(id, session)
        if response != Response.Success:
            return response
        if data.get('status'):
            status = data.get('status')
            lastCount += 1
            print(status, spinnerParts[lastCount % 4], end="\r")
            sys.stdout.flush()

            if status == "Accepted" or status == "Accepted (100)":
                runtime = data.get("runtime") or getRuntime(
                    id, problemName, session)
                printFinalStatus("๐Ÿ’š", status, runtime)
                break
            if status.startswith("Accepted"):
                runtime = data.get("runtime") or getRuntime(
                    id, problemName, session)
                printFinalStatus("๐ŸŸจ", status, runtime)
                break
            if status in _ERROR_MESSAGES.keys():
                runtime = data.get("runtime") or getRuntime(
                    id, problemName, session)
                print(
                    f"{_ERROR_MESSAGES[status].replace(' on @test of @total', '')} ({runtime})"
                )
                return Response.Error
        else:
            for _ in range(0, abs(lastCount - data["testCount"])):
                sys.stdout.write("๐Ÿ’š")
            sys.stdout.flush()

            if data["testTotal"] != 0 and data["testCount"] == data[
                    "testTotal"]:
                runtime = data.get("runtime")
                break

            lastCount = data["testCount"]

        time.sleep(0.5)

    if not runtime:
        runtime = getRuntime(id, problemName, session)

    print()
    print(
        "๐ŸŽ‰ Congratulations! You completed all",
        f"{str(data['testTotal']) + ' ' if 'testTotal' in data else ''}tests for",
        f"{problemName}{f' in {runtime}' if runtime else ''}!")
    return Response.Success
Esempio n. 5
0
def postSubmission(session, problemName, programFile):
    login(session)

    url = getConfigUrl("submissionurl", "submit")
    language = guessLanguage(programFile)

    if language == -1:
        print("Could not guess language for " + programFile)
        raise Exception("Could not guess language for " + programFile)

    language = formatLanguage(language)
    data = {
        "submit": "true",
        "submit_ctr": 2,
        "language": language,
        "problem": problemName,
        "script": "true",
    }

    if requiresClass(programFile):
        data["mainclass"] = detectClassName(programFile)

    sub_files = []
    undoBOM(programFile["relativePath"])
    with open(programFile["relativePath"]) as sub_file:
        sub_files.append((
            "sub_file[]",
            (programFile["name"], sub_file.read(), "application/octet-stream"),
        ))

    response = session.post(url, data=data, files=sub_files, headers=HEADERS)

    body = response.content.decode("utf-8").replace("<br />", "\n")
    match = re.search(r"Submission ID: ([0-9]+)", body)

    if match is None:
        print(
            "Submission was received, but could not read ID from response.",
            "Visit the submission manually in the browser.",
        )
        print("Response was: " + body)
        return -1

    return match.group(1).strip()
Esempio n. 6
0
def printUntilDone(id, problemName, session):
    lastCount = 0
    spinnerParts = ["-", "\\", "|", "/"]
    runtime = None

    print("โš–๏ธ  Submission Status:")

    while True:
        login(session)
        response, data = fetchNewSubmissionStatus(id, session)
        if response != Response.Success:
            return response
        if data.get('status'):
            status = data.get('status')
            lastCount += 1
            print(status, spinnerParts[lastCount % 4], end="\r")
            sys.stdout.flush()
            if status == "Accepted":
                runtime = data.get("runtime")
                print("\r๐Ÿ’š                ")  # clear line
                break
        else:
            for _ in range(0, abs(lastCount - data["testCount"])):
                sys.stdout.write("๐Ÿ’š")
            sys.stdout.flush()

            if data["testTotal"] != 0 and data["testCount"] == data[
                    "testTotal"]:
                runtime = data.get("runtime")
                break

            lastCount = data["testCount"]

        time.sleep(1)

    if not runtime:
        runtime = getRuntime(id, problemName, session)

    print()
    print(
        "๐ŸŽ‰ Congratulations! You completed all",
        f"{str(data['testTotal']) + ' ' if 'testTotal' in data else ''}tests for",
        f"{problemName}{f' in {runtime}' if runtime else ''}!")
    return Response.Success