main.py 8.0 KB

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