main.py 7.0 KB

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