babaTEEpe commited on
Commit
88cc391
·
verified ·
1 Parent(s): bfcf9fc

Update cloud_monitor.py

Browse files
Files changed (1) hide show
  1. cloud_monitor.py +50 -10
cloud_monitor.py CHANGED
@@ -271,23 +271,63 @@ async def run_monitor():
271
  continue
272
 
273
  # ============================================================
274
- # STEP 5: Extract match data (same selectors as local monitor)
 
 
 
 
275
  # ============================================================
276
- match_rows = await page.query_selector_all(
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
277
  "div.m-table-row.m-content-row.match-row.vFootball-row"
278
  )
279
- print(f" Found {len(match_rows)} match rows")
 
280
 
281
- if len(match_rows) < 10:
282
- print(f" Less than 10 matches, waiting for all to load...")
283
  await asyncio.sleep(10)
284
- match_rows = await page.query_selector_all(
285
- "div.m-table-row.m-content-row.match-row.vFootball-row"
286
- )
287
- print(f" Now found {len(match_rows)} match rows")
288
 
289
  matches_saved_this_cycle = 0
290
- for row in match_rows:
291
  try:
292
  # Get match time
293
  time_el = await row.query_selector("div.clock-time")
 
271
  continue
272
 
273
  # ============================================================
274
+ # STEP 5: Extract ONLY England Virtual match rows
275
+ # The page shows matches from ALL leagues (England, Spain,
276
+ # Italy, France). We need only the rows between the
277
+ # "England Virtual" header and the next league header.
278
+ # This replicates the local monitor's XPATH logic.
279
  # ============================================================
280
+ match_rows = await page.evaluate("""() => {
281
+ // Find all league headers and match rows
282
+ const headers = document.querySelectorAll('div.m-table-cell.league');
283
+ const allRows = document.querySelectorAll('div.m-table-row.m-content-row.match-row.vFootball-row');
284
+
285
+ // Find the England Virtual header position
286
+ let englandHeader = null;
287
+ let nextHeader = null;
288
+ let foundEngland = false;
289
+
290
+ for (const h of headers) {
291
+ if (h.textContent.includes('England Virtual')) {
292
+ englandHeader = h;
293
+ foundEngland = true;
294
+ } else if (foundEngland && !nextHeader) {
295
+ nextHeader = h;
296
+ }
297
+ }
298
+
299
+ if (!englandHeader) return [];
300
+
301
+ // Get the vertical position of England header and next header
302
+ const englandTop = englandHeader.getBoundingClientRect().top;
303
+ const nextTop = nextHeader ? nextHeader.getBoundingClientRect().top : 999999;
304
+
305
+ // Filter rows that are between England header and next header
306
+ const indices = [];
307
+ const rows = Array.from(allRows);
308
+ for (let i = 0; i < rows.length; i++) {
309
+ const rowTop = rows[i].getBoundingClientRect().top;
310
+ if (rowTop > englandTop && rowTop < nextTop) {
311
+ indices.push(i);
312
+ }
313
+ }
314
+ return indices;
315
+ }""")
316
+
317
+ # Now get only the England Virtual rows by index
318
+ all_rows = await page.query_selector_all(
319
  "div.m-table-row.m-content-row.match-row.vFootball-row"
320
  )
321
+ england_rows = [all_rows[i] for i in match_rows if i < len(all_rows)]
322
+ print(f" Found {len(england_rows)} England Virtual match rows (filtered from {len(all_rows)} total)")
323
 
324
+ if len(england_rows) < 10:
325
+ print(f" Less than 10 England matches, waiting...")
326
  await asyncio.sleep(10)
327
+ continue
 
 
 
328
 
329
  matches_saved_this_cycle = 0
330
+ for row in england_rows:
331
  try:
332
  # Get match time
333
  time_el = await row.query_selector("div.clock-time")