diff --git a/Bomb.py b/Bomb.py index 7b3e516..12fd814 100644 --- a/Bomb.py +++ b/Bomb.py @@ -1,5 +1,5 @@ import json -from datetime import time + import requests from requests.cookies import cookiejar_from_dict @@ -38,4 +38,4 @@ def run(self): cookie = cookiejar_from_dict(cookie_done) response = requests.get(url, data=data, headers=self.headers, cookies=cookie) if response.json()['code'] != '100000': - self.window.signal.emit(f'拉黑用户{uid}失败'+","+"{0}".format(response.json()['code'])) + self.window.signal.emit(f'拉黑用户{uid}失败' + "," + "{0}".format(response.json()['code'])) diff --git a/Cure.py b/Cure.py index adf9687..e879ca5 100644 --- a/Cure.py +++ b/Cure.py @@ -1,94 +1,95 @@ import random import time + from selenium.webdriver.common.by import By class Cure: - def __init__(self, window, driver, conf): - self.window = window - self.browser = driver - self.blackWords = conf.get("CURE", "blacklist") - self.whiteList = conf.get("CURE", "whitelist") - self.url = str(conf.get("CURE", "url")) - self.conf = conf - print(self.url) - self.treatment = [] - for n in open("comments.txt", 'r', encoding='utf-8').readlines(): - self.treatment.append(n) - self.window.signal.emit("话术加载完成") - - def getTreatment(self): - return self.treatment[random.randint(0, len(self.treatment) - 1)] - - def skip(self, text): - if len(text) > 120: - # 认为是正常发帖 - return True - for word in self.blackWords: - if text.find(word) != -1: - return True - return False - - def shouldHelp(self, text): - for word in self.whiteList: - if text.find(word) != -1: - return True - return False - - def work(self): - self.browser.get(self.url) - self.browser.implicitly_wait(5) - time.sleep(3) - - comments = self.browser.find_elements(By.CLASS_NAME, "WB_cardwrap")[1:] - while len(comments) == 0: - self.browser.implicitly_wait(3) - comments = self.browser.find_elements(By.CLASS_NAME, "WB_cardwrap")[1:] - if len(comments) > 10: - comments = comments[:10] - minApprove = 100 - minP = 0 - # self.window.signal.emit("comments length:" + str(len(comments))) - for i in range(len(comments)): - # self.window.signal.emit("===========================\n " + comments[i].text) - if self.skip(comments[i].text) or not self.shouldHelp(comments[i].text): - continue - if comments[i].text.split("\n")[-2].find('评论') == 1: - # 优先评论暂无评论的发布 - minP = i - break - currApprove = int(comments[i].text.split('\n')[-2].split(' ')[1]) - if currApprove < minApprove: - minApprove = currApprove - minP = i - - self.window.signal.emit("开始治疗 " + str(minP)) - comment = comments[minP] - self.browser.execute_script("arguments[0].scrollIntoView();", comment) - - try: - # 点赞 - comment.find_elements("class name", "pos")[3].click() - self.window.signal.emit("点赞 " + comment.text.split('\n')[2]) - time.sleep(3) - # 评论 - comment.find_elements("class name", "pos")[2].click() - time.sleep(3) - # 写入评论 - tmp = self.getTreatment() - left = right = 0 - while right < len(tmp): - # 模拟手打 - right = min(len(tmp), right + random.randint(1, 3)) - comment.find_element(By.CSS_SELECTOR, "textarea.W_input").send_keys(tmp[left:right]) - left = right - time.sleep(random.randint(1, 3) / 5) - time.sleep(3) - # 提交评论 - comment.find_element(By.CSS_SELECTOR, "a.W_btn_a").click() - self.window.signal.emit("评论 " + comment.text.split('\n')[2]) - except Exception as e: - e = e - self.window.signal.emit("治疗失败") - self.window.signal.emit("仅关注可评论") - self.work() + def __init__(self, window, driver, conf): + self.window = window + self.browser = driver + self.blackWords = conf.get("CURE", "blacklist") + self.whiteList = conf.get("CURE", "whitelist") + self.url = str(conf.get("CURE", "url")) + self.conf = conf + print(self.url) + self.treatment = [] + for n in open("comments.txt", 'r', encoding='utf-8').readlines(): + self.treatment.append(n) + self.window.signal.emit("话术加载完成") + + def getTreatment(self): + return self.treatment[random.randint(0, len(self.treatment) - 1)] + + def skip(self, text): + if len(text) > 120: + # 认为是正常发帖 + return True + for word in self.blackWords: + if text.find(word) != -1: + return True + return False + + def shouldHelp(self, text): + for word in self.whiteList: + if text.find(word) != -1: + return True + return False + + def work(self): + self.browser.get(self.url) + self.browser.implicitly_wait(5) + time.sleep(3) + + comments = self.browser.find_elements(By.CLASS_NAME, "WB_cardwrap")[1:] + while len(comments) == 0: + self.browser.implicitly_wait(3) + comments = self.browser.find_elements(By.CLASS_NAME, "WB_cardwrap")[1:] + if len(comments) > 10: + comments = comments[:10] + minApprove = 100 + minP = 0 + # self.window.signal.emit("comments length:" + str(len(comments))) + for i in range(len(comments)): + # self.window.signal.emit("===========================\n " + comments[i].text) + if self.skip(comments[i].text) or not self.shouldHelp(comments[i].text): + continue + if comments[i].text.split("\n")[-2].find('评论') == 1: + # 优先评论暂无评论的发布 + minP = i + break + currApprove = int(comments[i].text.split('\n')[-2].split(' ')[1]) + if currApprove < minApprove: + minApprove = currApprove + minP = i + + self.window.signal.emit("开始治疗 " + str(minP)) + comment = comments[minP] + self.browser.execute_script("arguments[0].scrollIntoView();", comment) + + try: + # 点赞 + comment.find_elements("class name", "pos")[3].click() + self.window.signal.emit("点赞 " + comment.text.split('\n')[2]) + time.sleep(3) + # 评论 + comment.find_elements("class name", "pos")[2].click() + time.sleep(3) + # 写入评论 + tmp = self.getTreatment() + left = right = 0 + while right < len(tmp): + # 模拟手打 + right = min(len(tmp), right + random.randint(1, 3)) + comment.find_element(By.CSS_SELECTOR, "textarea.W_input").send_keys(tmp[left:right]) + left = right + time.sleep(random.randint(1, 3) / 5) + time.sleep(3) + # 提交评论 + comment.find_element(By.CSS_SELECTOR, "a.W_btn_a").click() + self.window.signal.emit("评论 " + comment.text.split('\n')[2]) + except Exception as e: + e = e + self.window.signal.emit("治疗失败") + self.window.signal.emit("仅关注可评论") + self.work() diff --git a/Kill.py b/Kill.py index 074c03d..83f5427 100644 --- a/Kill.py +++ b/Kill.py @@ -1,70 +1,71 @@ import random import time + from selenium.webdriver.common.by import By class Kill: - def __init__(self, window, driver, conf): - self.window = window - self.browser = driver - self.url = str(conf.get("KILL", "url")) - self.conf = conf - print(self.url) - self.treatment = [] - for n in open("trashes.txt", 'r', encoding='utf-8').readlines(): - self.treatment.append(n) - self.window.signal.emit("话术加载完成") - self.comment_flag = False - self.tran_flag = False - - def getTreatment(self): - return self.treatment[random.randint(0, len(self.treatment) - 1)] - - def work(self): - self.browser.get(self.url) - self.browser.implicitly_wait(5) - time.sleep(3) - - comments = self.browser.find_elements(By.CLASS_NAME, "WB_cardwrap")[1:] - while len(comments) == 0: - self.browser.implicitly_wait(3) - comments = self.browser.find_elements(By.CLASS_NAME, "WB_cardwrap")[1:] - if len(comments) > 10: - comments = comments[:10] - minApprove = 100 - minP = 0 - # self.window.signal.emit("comments length:" + str(len(comments))) - - self.window.signal.emit("开始轰炸 " + str(minP)) - comment = comments[minP] - self.browser.execute_script("arguments[0].scrollIntoView();", comment) - - try: - # 转发 - if self.tran_flag: - comment.find_elements("class name", "pos")[0].click() - comment.find_element(By.CSS_SELECTOR, "a.W_btn_a").click() - self.window.signal.emit("转发 " + comment.text.split('\n')[2]) - time.sleep(3) - # 评论 - if self.comment_flag: - comment.find_elements("class name", "pos")[2].click() - time.sleep(3) - # 写入评论 - tmp = self.getTreatment() - left = right = 0 - while right < len(tmp): - # 模拟手打 - right = min(len(tmp), right + random.randint(1, 3)) - comment.find_element(By.CSS_SELECTOR, "textarea.W_input").send_keys(tmp[left:right]) - left = right - time.sleep(random.randint(1, 3) / 5) - time.sleep(3) - # 提交评论 - comment.find_element(By.CSS_SELECTOR, "a.W_btn_a").click() - self.window.signal.emit("评论 " + comment.text.split('\n')[2]) - except Exception as e: - e = e - self.window.signal.emit("轰炸失败") - self.window.signal.emit("仅关注可评论") - self.work() + def __init__(self, window, driver, conf): + self.window = window + self.browser = driver + self.url = str(conf.get("KILL", "url")) + self.conf = conf + print(self.url) + self.treatment = [] + for n in open("trashes.txt", 'r', encoding='utf-8').readlines(): + self.treatment.append(n) + self.window.signal.emit("话术加载完成") + self.comment_flag = False + self.tran_flag = False + + def getTreatment(self): + return self.treatment[random.randint(0, len(self.treatment) - 1)] + + def work(self): + self.browser.get(self.url) + self.browser.implicitly_wait(5) + time.sleep(3) + + comments = self.browser.find_elements(By.CLASS_NAME, "WB_cardwrap")[1:] + while len(comments) == 0: + self.browser.implicitly_wait(3) + comments = self.browser.find_elements(By.CLASS_NAME, "WB_cardwrap")[1:] + if len(comments) > 10: + comments = comments[:10] + minApprove = 100 + minP = 0 + # self.window.signal.emit("comments length:" + str(len(comments))) + + self.window.signal.emit("开始轰炸 " + str(minP)) + comment = comments[minP] + self.browser.execute_script("arguments[0].scrollIntoView();", comment) + + try: + # 转发 + if self.tran_flag: + comment.find_elements("class name", "pos")[0].click() + comment.find_element(By.CSS_SELECTOR, "a.W_btn_a").click() + self.window.signal.emit("转发 " + comment.text.split('\n')[2]) + time.sleep(3) + # 评论 + if self.comment_flag: + comment.find_elements("class name", "pos")[2].click() + time.sleep(3) + # 写入评论 + tmp = self.getTreatment() + left = right = 0 + while right < len(tmp): + # 模拟手打 + right = min(len(tmp), right + random.randint(1, 3)) + comment.find_element(By.CSS_SELECTOR, "textarea.W_input").send_keys(tmp[left:right]) + left = right + time.sleep(random.randint(1, 3) / 5) + time.sleep(3) + # 提交评论 + comment.find_element(By.CSS_SELECTOR, "a.W_btn_a").click() + self.window.signal.emit("评论 " + comment.text.split('\n')[2]) + except Exception as e: + e = e + self.window.signal.emit("轰炸失败") + self.window.signal.emit("仅关注可评论") + self.work() diff --git a/Main.py b/Main.py index 4423325..2678375 100644 --- a/Main.py +++ b/Main.py @@ -1,20 +1,17 @@ +import configparser import json -import multiprocessing import os import sys -import threading +import time +import pygame import requests -import PyQt5 -# from Cure import WeiboSpider -from Bomb import Black -from Cure import Cure -from Kill import Kill -from PyQt5 import QtCore, QtMultimedia -from PyQt5.QtCore import Qt, pyqtSignal, QUrl, QSize +from PyQt5 import QtCore +from PyQt5.QtCore import Qt, pyqtSignal, QSize from PyQt5.QtGui import QPixmap, QFontDatabase, QFont, QMouseEvent, QMovie from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QPushButton, QCheckBox, QLineEdit, QTextEdit -from Renew import Renew +from rich.console import Console +from rich.progress import track from selenium import webdriver from selenium.common.exceptions import TimeoutException from selenium.webdriver import EdgeOptions @@ -23,13 +20,14 @@ from selenium.webdriver.support import expected_conditions as condition from selenium.webdriver.support.ui import WebDriverWait from webdriver_manager.microsoft import EdgeChromiumDriverManager -import time -from rich.progress import track -from rich.console import Console -import configparser -import pygame -base_path = os.path.dirname(os.path.realpath(__file__)) +# from Cure import WeiboSpider +from Bomb import Black +from Cure import Cure +from Kill import Kill +from Renew import Renew + +base_path = os.path.dirname(os.path.realpath(sys.argv[0])) config_path = os.path.join(base_path, "conf.ini") conf = configparser.ConfigParser() conf.read(config_path, encoding="utf-8") @@ -40,6 +38,7 @@ _stop_event = threading.Event() + def stop(): global _stop_event _stop_event.set() @@ -99,7 +98,7 @@ def open_browser(url): def localize_scanner(self): self.open_browser("https://weibo.com/login.php") QR_tab = wait.until(condition.element_to_be_clickable((By.XPATH, '//*[@id="pl_login_form"]' - '/div/div[1]/div/a[2]'))) + '/div/div[1]/div/a[2]'))) [QR_tab.click() for i in range(2)] QR = wait.until(condition.presence_of_element_located((By.CSS_SELECTOR, "#pl_login_form > div > " "div.login_content > img"))) @@ -481,7 +480,7 @@ def heal(): self.cure.work() times += 1 window.signal.emit("第{:d}次工作结束,开始睡眠".format(times)) - time.sleep(int(conf.get("CURE", "sleep_second"))) + time.sleep(int(conf.get("CURE", "sleep_seconds"))) if stopped(): return True diff --git a/Renew.py b/Renew.py index ff6800f..ec3f3b1 100644 --- a/Renew.py +++ b/Renew.py @@ -1,9 +1,5 @@ import time -from selenium import webdriver -from selenium.webdriver.edge.options import Options -from selenium.webdriver.edge.service import Service - class Renew: def __init__(self, driver, conf): @@ -44,4 +40,3 @@ def create_tag(self, url): self.refresh_tag() self.driver.switch_to.window(self.driver.window_handles[0]) # https://s.weibo.com/weibo?q=%23A-SOUL%E6%88%90%E5%91%98%E9%81%AD%E9%81%87%E5%85%AC%E5%8F%B8PUA%23 - diff --git a/tubiao.ico b/tubiao.ico new file mode 100644 index 0000000..cab3722 Binary files /dev/null and b/tubiao.ico differ