Ejemplo n.º 1
0
def ignore_url(current_url):
    global PreviousURL
    global AttemptGetOdds
    global ErrorLoadURL
    if current_url == PreviousURL:
        log_path = odds_options.error_log_path()
        if not os.path.isfile(log_path):
            AttemptGetOdds += 1
        else:
            log_file = open(log_path)
            content = log_file.readlines()[-2 - ErrorLoadURL:-1]
            log_file.close()
            last_lines_contain_url = [
                line for line in content if current_url in line
            ]
            if len(last_lines_contain_url) == ErrorLoadURL + 1:
                ErrorLoadURL += 1
            else:
                AttemptGetOdds += 1
        if ErrorLoadURL == odds_options.MAX_ERRORS_LOAD_URL:
            print 'The maximum number of faulty downloads reached.'
            exit()
        if AttemptGetOdds == odds_options.MAX_ATTEMPTS_GET_ODDS:
            if not is_url_ignored(current_url):
                ignored_file = open(odds_options.ignored_urls_path(), 'a')
                ignored_file.write(current_url + '\n')
                ignored_file.close()
            ErrorLoadURL = 0
            AttemptGetOdds = 0
            return True
    else:
        ErrorLoadURL = 0
        AttemptGetOdds = 0
        PreviousURL = current_url
    return False
Ejemplo n.º 2
0
Archivo: odds.py Proyecto: krylov/sport
def ignore_url(current_url):
    global PreviousURL
    global AttemptGetOdds
    global ErrorLoadURL
    if current_url == PreviousURL:
        log_path = odds_options.error_log_path()
        if not os.path.isfile(log_path):
            AttemptGetOdds += 1
        else:
            log_file = open(log_path)
            content = log_file.readlines()[-2 - ErrorLoadURL : -1]
            log_file.close()
            last_lines_contain_url = [line for line in content if current_url in line]
            if len(last_lines_contain_url) == ErrorLoadURL + 1:
                ErrorLoadURL += 1
            else:
                AttemptGetOdds += 1
        if ErrorLoadURL == odds_options.MAX_ERRORS_LOAD_URL:
            print "The maximum number of faulty downloads reached."
            exit()
        if AttemptGetOdds == odds_options.MAX_ATTEMPTS_GET_ODDS:
            if not is_url_ignored(current_url):
                ignored_file = open(odds_options.ignored_urls_path(), "a")
                ignored_file.write(current_url + "\n")
                ignored_file.close()
            ErrorLoadURL = 0
            AttemptGetOdds = 0
            return True
    else:
        ErrorLoadURL = 0
        AttemptGetOdds = 0
        PreviousURL = current_url
    return False
Ejemplo n.º 3
0
def is_url_ignored(url):
    ignored_path = odds_options.ignored_urls_path()
    if not os.path.isfile(ignored_path):
        return False
    ignored_file = open(ignored_path)
    content = ignored_file.readlines()
    content = [line.replace('\n', '') for line in content]
    url_is_ignored = url in content
    ignored_file.close()
    return url_is_ignored
Ejemplo n.º 4
0
Archivo: odds.py Proyecto: krylov/sport
def is_url_ignored(url):
    ignored_path = odds_options.ignored_urls_path()
    if not os.path.isfile(ignored_path):
        return False
    ignored_file = open(ignored_path)
    content = ignored_file.readlines()
    content = [line.replace("\n", "") for line in content]
    url_is_ignored = url in content
    ignored_file.close()
    return url_is_ignored