def run(self): '''Запуск''' while True: if self.flag.is_set(): break ######### with self.lock: try: proxy = self.proxies.input.pop() except IndexError: break except Exception as e: raise e ############################# status, answer = self.checker.request(proxy, self.protocol) ############ if status: if self.checker.answerStatus(answer): print(self.checker.NAME + coloring(f"[{self.proxies.getStat()}]Найдена рабочая прокси: {proxy}", "green")) with self.lock: self.proxies.green.append(proxy) else: print(self.checker.NAME + coloring(f"[{self.proxies.getStat()}]Найдена прокси с блеклист ASN: {proxy}", "yellow")) with self.lock: self.proxies.bad.append(proxy) else: print(self.checker.NAME + coloring(f"[{self.proxies.getStat()}]Нерабочая прокси: {proxy}", "white")) with self.lock: self.proxies.died.append(proxy)
def main(proxies, protocol): '''bans checker threading main''' checker = Check() lock = threading.Lock() _proxies = Proxies(proxies) _threads = checker.TASKS flag = threading.Event() threads = [] print(checker.NAME + coloring("Проверка на баны началась...", "green")) ############################## for i in range(0, _threads + 1): _ = CheckerThread(_proxies, protocol, checker, lock, flag) threads.append(_) _.setDaemon(True) _.start() ######### try: for i in threads: i.join() except KeyboardInterrupt: print(checker.NAME + coloring( "Проверка отменена! Завершение всех потоков...", "yellow")) flag.set() while True: threads = threading.enumerate() if len(threads) > 1: time.sleep(2) else: break except Exception as e: logwrite.log(e, "main threading_ban_checker") else: print(checker.NAME + coloring("Проверка на баны закончена!", "green")) with open("trashproxies/died.txt", mode="a", encoding="UTF-8") as file: for i in _proxies.died: file.write(i + "\n") ######################################################################### with open("trashproxies/banned.txt", mode="a", encoding="UTF-8") as file: for i in _proxies.banned: file.write(i + "\n") ########################################################## print(checker.NAME + coloring( f"Записаны нерабочие прокси в trashproxies/died.txt {str(len(_proxies.died))} единиц.", "green")) print(checker.NAME + coloring( f"Записаны забаненные прокси в trashproxies/banned.txt {str(len(_proxies.banned))} единиц.", "green")) return _proxies.green
def answerStatus(self, response): ''' Анализ ответа на [данные удалены] ''' if "Тред не существует." in response: return False elif "OK" in response: return True elif "Плановые техработы" in response: time.sleep(30) print(self.NAME + coloring(f"Техработы.", "red")) return False else: print(self.NAME + coloring(f"Нестандартный ответ: {str(response)}", "red")) return False