main.py 8.6 KB

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