def rename_old_error_log(): log_path = odds_options.error_log_path() if os.path.isfile(log_path): n = 1 while os.path.isfile(log_path + "." + str(n) + ".old"): n += 1 os.rename(log_path, log_path + "." + str(n) + ".old")
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
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