StarrySkyWorld commited on
Commit
3f3549a
·
verified ·
1 Parent(s): dc41b5b

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +20 -9
main.py CHANGED
@@ -81,27 +81,23 @@ async def auto_click_task():
81
  return
82
 
83
  try:
84
- # 查找包含 "Got it" 文本的按钮
85
  selectors = [
86
  'button:has-text("Got it")',
87
  'a:has-text("Got it")',
88
  '[role="button"]:has-text("Got it")',
89
- 'input[type="button"][value="Got it"]',
90
- 'input[type="submit"][value="Got it"]',
91
  ]
92
 
93
  for selector in selectors:
94
  try:
95
  element = page.locator(selector).first
96
- if await element.is_visible(timeout=500):
97
- await element.click()
98
  print(f'[AutoClick] Clicked "Got it" button')
99
  return
100
  except:
101
  continue
102
 
103
- except Exception as e:
104
- # 静默处理,避免日志刷屏
105
  pass
106
 
107
  async def init_browser():
@@ -165,11 +161,26 @@ async def lifespan(app: FastAPI):
165
  # 定时激活任务
166
  if config and config.get("activateLink"):
167
  interval = config.get("activateInterval", 60)
168
- scheduler.add_job(activate_task, "interval", seconds=interval)
 
 
 
 
 
 
 
169
  print(f"[Scheduler] Activate task started with interval: {interval}s")
170
 
171
  # 自动点击 "Got it" 按钮任务
172
- scheduler.add_job(auto_click_task, "interval", seconds=5)
 
 
 
 
 
 
 
 
173
  print(f"[Scheduler] Auto-click task started with interval: 5s")
174
 
175
  scheduler.start()
 
81
  return
82
 
83
  try:
 
84
  selectors = [
85
  'button:has-text("Got it")',
86
  'a:has-text("Got it")',
87
  '[role="button"]:has-text("Got it")',
 
 
88
  ]
89
 
90
  for selector in selectors:
91
  try:
92
  element = page.locator(selector).first
93
+ if await element.is_visible(timeout=200):
94
+ await element.click(timeout=1000)
95
  print(f'[AutoClick] Clicked "Got it" button')
96
  return
97
  except:
98
  continue
99
 
100
+ except:
 
101
  pass
102
 
103
  async def init_browser():
 
161
  # 定时激活任务
162
  if config and config.get("activateLink"):
163
  interval = config.get("activateInterval", 60)
164
+ scheduler.add_job(
165
+ activate_task,
166
+ "interval",
167
+ seconds=interval,
168
+ max_instances=1,
169
+ coalesce=True,
170
+ misfire_grace_time=30
171
+ )
172
  print(f"[Scheduler] Activate task started with interval: {interval}s")
173
 
174
  # 自动点击 "Got it" 按钮任务
175
+ scheduler.add_job(
176
+ auto_click_task,
177
+ "interval",
178
+ seconds=5,
179
+ max_instances=1,
180
+ coalesce=True,
181
+ misfire_grace_time=10,
182
+ replace_existing=True
183
+ )
184
  print(f"[Scheduler] Auto-click task started with interval: 5s")
185
 
186
  scheduler.start()