Ejemplo n.º 1
0
def problems():
    display_strings = []
    click.echo("requesting problem list from server...")
    if(session.is_logged_in()):
        display_strings.append(style.normal(
            "You are logged in\n" +
            "Only UNSOLVED problems are being displayed"))
    else:
        display_strings.append(style.normal("you are NOT logged in\n" +
                                            "displaying ALL the problems"))
    # the following line involves a request
    # problems are unsolved ones if logged in
    problems = scrape.get_problem_list()
    click.echo("Done")
    display_strings.append(division_line())
    display_strings.append("|"+style.sno("SNo", 3) +
                           "|"+style.problem_code("Code", 10) +
                           "|"+style.unsolved("Name", 25)+"|")
    display_strings.append(division_line())
    for (sno, problem) in zip(range(len(problems)), problems):
        display_strings.append(
                    "|"+style.sno(str(sno+1), 3) +
                    "|"+style.problem_code(problem["problem_code"], 10) +
                    "|"+style.unsolved(problem["problem_name"], 25)+"|")
    display_strings.append(division_line())
    click.echo_via_pager('\n'.join(display_strings))
Ejemplo n.º 2
0
def setup_all_problems(confirm=True):
    if (confirm):
        click.confirm("You have not passed any flag to iarcs.\n" +
                      "Do you want to setup all problems?",
                      default=True,
                      abort=True)
    click.echo("trying to get your login status...", nl=False)
    status = session.is_logged_in(ensure=True)

    if (status):
        display.normal("\tDone\nYou are currently logged in, " +
                       "only unsolved problems will be setup")
    elif (status is False):
        display.normal("\tDone\nYou are currently logged out, " +
                       "all problems will be setup")
    else:
        display.error("Cannot determine login status\n" +
                      "Pls check your internet connection")
        sys.exit()

    cwd = os.getcwd()
    try:
        os.mkdir("iarcs")
    except BaseException:
        pass
    os.chdir("iarcs")
    click.echo("fetching problem list... ", nl=False)
    problem_list = scrape.get_problem_list()
    click.echo("\tDone")
    display.normal("setting up %d problems from iarcs..." % len(problem_list))
    with click.progressbar(problem_list) as bar:
        for problem in bar:
            setup_problem(problem["problem_code"])
    os.chdir(cwd)
Ejemplo n.º 3
0
def logout():
    if (not session.is_logged_in(ensure=False)):
        display.normal("invalid option --logout")
        display.normal("you are already logged out of iarcs")
    else:
        display.normal("logging you out of iarcs. please wait...")
        session.logout()
        display.normal("you were logged out sucessfully. cookies deleted")
Ejemplo n.º 4
0
def login():
    click.echo("trying to get your login page...")
    if (session.is_logged_in(ensure=True)):
        display.normal("You are already logged in")
    else:
        username = click.prompt('enter username', type=click.STRING)
        password = click.prompt('enter password',
                                type=click.STRING,
                                hide_input=True)
        display.normal("logging you into iarcs. please wait...")
        session.login(username, password)
        display.normal("you were logged in successfully. cookies saved")
Ejemplo n.º 5
0
def get_problem_list():
    iarcs_session = session.iarcs_session
    logged_in = (session.is_logged_in())
    url = "http://opc.iarcs.org.in/index.php/problems/"
    try:
        r = iarcs_session.get(url)
        soup = BeautifulSoup(r.text, "html.parser")
    except BaseException:
        display.url_error(url, abort=True)
    else:
        unsolved_list = []
        problem_rows = soup.find_all("tr")[1:-1]    # 0th row contains heading
        for problem in problem_rows:
            row_data = problem.find_all("td")
            code_data, problem_data = row_data[1], row_data[2]
            status = None
            if(logged_in):
                status = row_data[3].text
            if(not status):
                unsolved_list.append({"problem_code": code_data.a.text,
                                      "problem_name": problem_data.a.text})
        return unsolved_list
Ejemplo n.º 6
0
def submit(code_file):
    iarcs_session = session.iarcs_session
    problem_file = open(".problem")
    j = json.load(problem_file)
    submit_url = "http://opc.iarcs.org.in/index.php/submit/upload"

    probid = j["problem_code"]
    source = open(str(code_file), "rb")
    extension = os.path.splitext(code_file)[1]
    try:
        lang = lang_map[extension]
    except BaseException:
        click.echo("the following extension is not supported:"
                   + extension)
        sys.exit()

    files = {
        "source": source
    }

    data = {
        "MAX_FILE_SIZE": "100000",
        "probid": probid,
        "lang": lang
    }

    # final confirmation
    click.confirm("following problem will be submitted\n" +
                  "judge: iarcs\n" +
                  "problem code: "+probid+"\n" +
                  "file: "+str(code_file)+"\n" +
                  "lang: "+lang+"\n"
                  "Are you sure?", default=True, abort=True)

    display.normal("checking your login...")
    login_status = session.is_logged_in(ensure=True)
    if(login_status is False):
        display.normal("You are NOT logged in. Redirecting to login...")
        setup_module.login()
    elif(login_status):
        display.normal("You are logged in")
    else:
        display.error("cannot determine login status\n" +
                      "please check your internet connection")
        sys.exit()
    click.echo("submitting your solution...", nl=False)
    # TODO: test before submit and confirm
    try:
        r = iarcs_session.post(submit_url, files=files, data=data)
    except BaseException:
        display.url_error(submit_url, abort=True)

    display.normal("\tDone")
    click.echo(
        "retriving status (you can continue your work in another tab)...",
        nl=False)

    submission_code = get_submission_code(r.text)
    status, points = check_status(submission_code)
    click.echo("\tDone")
    click.echo("status: "+status)
    click.echo("points: "+points)