main.py 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. import ctypes
  2. import platform
  3. import subprocess
  4. import sys
  5. import os
  6. import threading
  7. import time
  8. from datetime import datetime
  9. from PyQt5.QtCore import Qt, QUrl, QDateTime
  10. from PyQt5.QtWidgets import QApplication, QMainWindow, QLabel, QFileDialog, QMessageBox, QDateTimeEdit, QPushButton
  11. from PyQt5.QtGui import QDesktopServices
  12. from app import login_account, run_threading_order, run_daily_job, run_manual_job, cancel_manual_job, stop_order_job, \
  13. write_ticket_info
  14. from litter_helper import Ui_menu # 确保这个导入路径是正确的
  15. from tools.utils import save_all_proxy_ip_v3
  16. import winreg
  17. # 定义 Redis 安装程序路径
  18. REDIS_INSTALLER_PATH = "Redis-x64-5.0.14.1.msi" # 替换为实际的安装程序路径
  19. class ClickableLabel(QLabel):
  20. def __init__(self, parent=None, file_path=None):
  21. super().__init__(parent)
  22. self.file_path = file_path
  23. def mousePressEvent(self, event):
  24. if event.button() == Qt.LeftButton:
  25. self.emit_click_event()
  26. def emit_click_event(self):
  27. if self.file_path:
  28. self.parent().on_label_click(self.file_path)
  29. def get_resource_path(relative_path):
  30. """获取资源文件的绝对路径"""
  31. if getattr(sys, 'frozen', False): # 是否为PyInstaller打包的exe文件
  32. # 返回exe文件所在的绝对路径
  33. base_path = os.path.dirname(sys.executable)
  34. else: # 在开发环境下运行
  35. # 返回脚本文件所在的绝对路径
  36. base_path = os.path.dirname(__file__)
  37. return os.path.join(base_path, relative_path)
  38. # 停止定时任务
  39. def on_stop_time_button_click():
  40. print(f"停止定时任务: {time.time()}")
  41. cancel_manual_job()
  42. # 写入文件
  43. def on_write_file_button_click():
  44. print(f"写入文件:{time.time()}")
  45. write_ticket_info("abcd", "1234556")
  46. class MainWindow(QMainWindow, Ui_menu):
  47. def __init__(self, param1, param2):
  48. super().__init__()
  49. self.setupUi(self)
  50. # 使用传递的参数
  51. self.param1 = param1
  52. self.param2 = param2
  53. # 设置标签的文本为传递的参数
  54. # self.label.setText(f"参数1: {self.param1}, 参数2: {self.param2}")
  55. self.concurrencyLineEdit.setText("1")
  56. self.urlLineEdit.setText("https://t.livepocket.jp/e/l3im7")
  57. # 登录账号
  58. self.loginPushButton.clicked.connect(self.on_login_button_click)
  59. # 开始下单
  60. self.startPushButton.clicked.connect(self.on_start_button_click)
  61. # 停止下单
  62. self.stopOrderPushButton.clicked.connect(self.on_stop_button_click)
  63. # 定时开始
  64. self.startTimePushButton.clicked.connect(self.on_start_time_button_click)
  65. # 停止定时任务
  66. self.stopTimePushButton.clicked.connect(on_stop_time_button_click)
  67. # 写入文件
  68. # self.writeFilePushButton.clicked.connect(on_write_file_button_click)
  69. # 编辑账号
  70. # 获取 QLabel 控件并替换为 ClickableLabel
  71. self.accountsLabel = self.findChild(QLabel, "accountsLabel")
  72. if self.accountsLabel:
  73. # 替换为 ClickableLabel
  74. self.clickableAccountsLabel = ClickableLabel(self, file_path=get_resource_path("accounts.txt"))
  75. self.clickableAccountsLabel.setObjectName("accountsLabel")
  76. self.clickableAccountsLabel.setText("编辑账号")
  77. self.clickableAccountsLabel.setGeometry(self.accountsLabel.geometry())
  78. self.clickableAccountsLabel.show()
  79. self.accountsLabel.deleteLater() # 删除原来的 QLabel 控件
  80. # 编辑IP代理池
  81. # 获取 QLabel 控件并替换为 ClickableLabel
  82. self.ipPoolLabel = self.findChild(QLabel, "ipPoolLabel")
  83. if self.ipPoolLabel:
  84. # 替换为 ClickableLabel
  85. self.clickableIpPoolLabel = ClickableLabel(self, file_path=get_resource_path("proxy_list.txt"))
  86. self.clickableIpPoolLabel.setObjectName("ipPoolLabel")
  87. self.clickableIpPoolLabel.setText("编辑代理池")
  88. self.clickableIpPoolLabel.setGeometry(self.ipPoolLabel.geometry())
  89. self.clickableIpPoolLabel.show()
  90. self.ipPoolLabel.deleteLater() # 删除原来的 QLabel 控件
  91. # 获取 QDateTimeEdit 控件并设置显示格式
  92. self.startDateTimeEdit = self.findChild(QDateTimeEdit, "startDateTimeEdit")
  93. if self.startDateTimeEdit:
  94. self.startDateTimeEdit.setDisplayFormat("yyyy-MM-dd HH:mm:ss")
  95. # 设置当前时间
  96. self.startDateTimeEdit.setDateTime(QDateTime.currentDateTime())
  97. # 获取 QDateTimeEdit 控件并设置显示格式
  98. self.endDateTimeEdit = self.findChild(QDateTimeEdit, "endDateTimeEdit")
  99. if self.endDateTimeEdit:
  100. self.endDateTimeEdit.setDisplayFormat("yyyy-MM-dd HH:mm:ss")
  101. # 设置当前时间
  102. self.endDateTimeEdit.setDateTime(QDateTime.currentDateTime())
  103. # 连接 watchPushButton 点击事件到槽函数
  104. self.watchPushButton = self.findChild(QPushButton, "watchPushButton")
  105. if self.watchPushButton:
  106. self.watchPushButton.clicked.connect(self.on_watch_button_click)
  107. # 检查 Redis 是否安装
  108. self.check_redis_installation()
  109. def on_label_click(self, file_path):
  110. if os.path.exists(file_path):
  111. try:
  112. QDesktopServices.openUrl(QUrl.fromLocalFile(file_path))
  113. except Exception as e:
  114. QMessageBox.critical(self, "Error", f"无法打开文件: {e}")
  115. else:
  116. QMessageBox.critical(self, "Error", f"文件不存在: {file_path}")
  117. def on_start_button_click(self):
  118. print(f"开始下单!")
  119. # 在按钮点击时执行的操作
  120. # print(f"按钮被点击了!参数1: {self.param1}, 参数2: {self.param2}")
  121. # 获取 QDateTimeEdit 控件的值
  122. if self.startDateTimeEdit:
  123. date_time_value = self.startDateTimeEdit.dateTime()
  124. # print(f"选中的日期和时间: {date_time_value.toString('yyyy-MM-dd HH:mm:ss')}")
  125. # 获取 QDateTimeEdit 控件的值
  126. if self.endDateTimeEdit:
  127. date_time_value = self.endDateTimeEdit.dateTime()
  128. # print(f"选中的日期和时间: {date_time_value.toString('yyyy-MM-dd HH:mm:ss')}")
  129. # 获取并发数
  130. thread_num = 1
  131. if self.concurrencyLineEdit:
  132. # print(f"并发数为: {self.concurrencyLineEdit.text()}")
  133. thread_num = self.concurrencyLineEdit.text()
  134. # url
  135. net_url = None
  136. if self.urlLineEdit:
  137. net_url = self.urlLineEdit.text()
  138. # 下单
  139. run_threading_order(thread_num, get_resource_path("accounts.txt"), net_url)
  140. # 登录账号
  141. def on_login_button_click(self):
  142. print(f"登录账号! {self.urlLineEdit.text()}")
  143. thread_num = 1
  144. if self.concurrencyLineEdit.text():
  145. thread_num = self.concurrencyLineEdit.text()
  146. pocket_url = None
  147. if self.urlLineEdit.text():
  148. pocket_url = self.urlLineEdit.text()
  149. save_all_proxy_ip_v3(get_resource_path("proxy_list.txt"))
  150. login_account(thread_num, get_resource_path("accounts.txt"), pocket_url)
  151. else:
  152. QMessageBox.warning(self, '警告', '请输入URL')
  153. return
  154. # 定时开始
  155. def on_start_time_button_click(self):
  156. print(f"定时开始:{time.time()}")
  157. net_url = None
  158. if self.urlLineEdit:
  159. net_url = self.urlLineEdit.text()
  160. start_time = self.startDateTimeEdit.text()
  161. print(f"start_time:{start_time}")
  162. # 使用datetime模块解析时间字符串
  163. dt = datetime.strptime(start_time, '%Y-%m-%d %H:%M:%S')
  164. # 提取出时、分、秒
  165. hour = dt.hour
  166. minute = dt.minute
  167. second = dt.second
  168. print(f"Hour: {hour}, Minute: {minute}, Second: {second}")
  169. # 创建一个新的线程来运行 run_manual_job 函数
  170. thread = threading.Thread(target=run_manual_job, args=(hour, minute, net_url))
  171. thread.start()
  172. else:
  173. QMessageBox.warning(self, '警告', '请输入URL')
  174. return
  175. # 终止下单
  176. def on_stop_button_click(self):
  177. print(f"终止下单! 目标网址: {self.urlLineEdit.text()}")
  178. stop_order_job()
  179. def edit_accounts(self):
  180. # 编辑账号
  181. print(f"编辑账号: {self.urlLineEdit.text()}")
  182. # 查看结果
  183. def on_watch_button_click(self):
  184. # 获取项目当前路径
  185. current_path = sys.path[0]
  186. # 拼接文件夹路径
  187. folder_path = get_resource_path("results") # 假设文件夹名为 "results"
  188. try:
  189. # 使用 QDesktopServices.openUrl 打开文件夹
  190. QDesktopServices.openUrl(QUrl.fromLocalFile(folder_path))
  191. except Exception as e:
  192. QMessageBox.critical(self, "Error", f"无法打开文件夹: {e}")
  193. # 检查 Redis 是否安装
  194. def check_redis_installation(self):
  195. # 检查操作系统
  196. system = platform.system()
  197. if system == "Windows":
  198. # 检查 Redis 服务是否正在运行
  199. try:
  200. key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, r"SYSTEM\CurrentControlSet\Services\Redis")
  201. winreg.CloseKey(key)
  202. print("Redis 服务已安装并正在运行")
  203. return
  204. except FileNotFoundError as ex:
  205. print(f"Redis 服务未安装或未运行")
  206. # 如果 Redis 服务未安装,则启动安装程序
  207. if REDIS_INSTALLER_PATH:
  208. try:
  209. subprocess.run([REDIS_INSTALLER_PATH], shell=True)
  210. print("Redis 安装程序已启动")
  211. except Exception as e:
  212. QMessageBox.critical(self, "Error", f"无法启动 Redis 安装程序: {e}")
  213. else:
  214. # 在其他操作系统上,可以使用不同的方法检查 Redis 是否安装
  215. # 例如,可以使用 `which redis-server` 命令
  216. print("当前操作系统不支持自动安装 Redis")
  217. if __name__ == "__main__":
  218. app = QApplication(sys.argv)
  219. # 创建窗口并传递参数
  220. window = MainWindow("Hello", "World")
  221. window.show()
  222. sys.exit(app.exec_())