Exemple #1
0
def try_parse(parse_func, source, site_name, **kwargs):
    try:
        result = parse_func(source, **kwargs)
    except Exception as err:
        if not isinstance(
                err,
                KeyboardInterrupt):  # if it wasn't a forced stop of a program
            logging.error("error occurred in parsing({}): {}".format(
                site_name, str(err)))

            filename = os.path.join(project_dir,
                                    "error-parsing-{}".format(site_name))
            with open(filename, "w") as out:
                out.write(format_exc())

            # saving parsing sample
            filename = os.path.join(
                project_dir, "error-parsing-{}-sample".format(site_name))

            if not isinstance(source, str):  # if sample is not html
                source = obj_dumps(source)
                filename += ".json"

            with open(filename, "w") as out:
                out.write(source)
        raise
    return result
Exemple #2
0
def test_known_result():
    surebets_other, surebets_posit = read_sample("known.pkl")
    exclude_posit(surebets_other, surebets_posit)

    with open(path.join(resource_dir, "knownResult.json")) as file_result:
        surebets_result = json.load(file_result)

    assert obj_dumps(surebets_other) == json_dumps(surebets_result)

    logging.info("PASS: known")
Exemple #3
0
def test_known_result():
    with open(path.join(resource_dir, "known.json")) as file_known:
        sample_known = json.load(file_known)
    surebets_posit = mock_load_events(sample_known)

    with open(path.join(resource_dir,
                        "knownResult.json")) as file_known_result:
        surebets_known = json.load(file_known_result)

    assert obj_dumps(surebets_posit) == json_dumps(surebets_known)

    logging.info("PASS: known result")
Exemple #4
0
def test_parse_json():
    sample_html = read_sample(name, FILENAME_PATTERN.format('.html'))
    sample_json = read_sample(name, FILENAME_PATTERN.format('.json'))

    bookmaker = Bookmaker(name)
    parse(sample_html, bookmaker)
    parse_json(sample_json, bookmaker)

    result = read_sample(name, FILENAME_PATTERN.format('result.json'))
    assert json_dumps(result) == obj_dumps(bookmaker)

    logging.info('PASS: known result')
Exemple #5
0
def test_known_result():
    filename = abs_path(name, 'knownResultIn.html')
    html = read_html(filename)

    filename = abs_path(name, 'knownResultOut.json')
    known_result = read_json(filename)

    surebets = try_parse(parse, html, name)

    assert obj_dumps(surebets) == json_dumps(known_result)

    logging.info('PASS: known result')
Exemple #6
0
def test_known_result(name, known_result_in_file_extension):
    parse = import_module('surebet.parsing.' + name).parse

    known_result_in = read_sample(name, 'knownResultIn.' + known_result_in_file_extension)
    known_result_out = read_sample(name, 'knownResultOut.json')

    bookmaker = Bookmaker(name)
    try_parse(parse, known_result_in, name, bookmaker=bookmaker)
    bookmaker.format()

    assert obj_dumps(bookmaker) == json_dumps(known_result_out)

    logging.info('PASS: known result')
Exemple #7
0
def test_known_result():
    filename = path.join(resource_dir, "knownResult.json")
    with open(filename) as file:
        known_res = json.load(file)

    filename = path.join(resource_dir, "knownResult.pkl")
    with open(filename, "rb") as file:
        known_res_sample = pickle.load(file)

    surebets = calc_surebets(*known_res_sample)

    assert obj_dumps(surebets) == json_dumps(known_res)

    logging.info("PASS: known result")
Exemple #8
0
def test_decrease_known():
    with open(path.join(resource_dir, 'knownDecrease.json')) as file_known:
        surebets = json.load(file_known, cls=SurebetsJSONDecoder)

    posit = mock_posit()
    posit.surebets = surebets
    mock_decrease_marks(posit)

    with open(path.join(resource_dir,
                        'knownDecreaseResult.json')) as file_known_result:
        surebets_known = json.load(file_known_result)

    assert obj_dumps(posit.surebets) == json_dumps(surebets_known)

    logging.info("PASS: decrease and restore")
Exemple #9
0
def test_searching():
    fonbet_html = read_html('fonbet')
    fonbet_json = read_json('fonbet')
    marat_json = read_json('marat')
    olimp_json = read_json('olimp')

    bookmakers = Bookmakers()
    fonbet_parse(fonbet_html, bookmakers.fonbet)
    fonbet_parse_json(fonbet_json, bookmakers.fonbet)
    marat_parse(marat_json, bookmakers.marat)
    olimp_parse(olimp_json, bookmakers.olimp)

    surebets = find_surebets(bookmakers)
    surebets_known = read_json('surebets')

    assert obj_dumps(surebets) == json_dumps(surebets_known)