AuthorBot Cursor commited on
Commit
b6b3216
·
1 Parent(s): 7698f17

debug: instrument platform presence scan for missing listings regression

Browse files
app/services/isbn_catalog.py CHANGED
@@ -487,9 +487,33 @@ async def verify_isbn_anchor(
487
  snippet = (resp.text or "")[:120_000].lower()
488
  tokens = [t for t in re.sub(r"[^\w\s]", " ", core).split() if len(t) > 3]
489
  if tokens and sum(1 for t in tokens[:3] if t.lower() in snippet) < 2:
 
 
 
 
 
 
 
 
490
  return None
 
 
 
 
 
 
 
 
491
  return clean
492
  except Exception as exc:
 
 
 
 
 
 
 
 
493
  logger.debug(
494
  "ISBN anchor verify failed",
495
  platform=platform_id,
 
487
  snippet = (resp.text or "")[:120_000].lower()
488
  tokens = [t for t in re.sub(r"[^\w\s]", " ", core).split() if len(t) > 3]
489
  if tokens and sum(1 for t in tokens[:3] if t.lower() in snippet) < 2:
490
+ # #region agent log
491
+ try:
492
+ import time as _tv, json as _jv
493
+ with open("debug-7c8974.log", "a") as _fv:
494
+ _fv.write(_jv.dumps({"sessionId":"7c8974","hypothesisId":"A","location":"isbn_catalog.py:verify_isbn_anchor","message":"anchor_title_fail","data":{"platform":platform_id,"anchor":anchor,"final":final,"clean":clean,"found_tokens":sum(1 for t in tokens[:3] if t.lower() in snippet)},"timestamp":int(_tv.time()*1000)}) + "\n")
495
+ except Exception:
496
+ pass
497
+ # #endregion
498
  return None
499
+ # #region agent log
500
+ try:
501
+ import time as _tv2, json as _jv2
502
+ with open("debug-7c8974.log", "a") as _fv2:
503
+ _fv2.write(_jv2.dumps({"sessionId":"7c8974","hypothesisId":"A","location":"isbn_catalog.py:verify_isbn_anchor","message":"anchor_success","data":{"platform":platform_id,"anchor":anchor,"final":final,"clean":clean,"status":resp.status_code},"timestamp":int(_tv2.time()*1000)}) + "\n")
504
+ except Exception:
505
+ pass
506
+ # #endregion
507
  return clean
508
  except Exception as exc:
509
+ # #region agent log
510
+ try:
511
+ import time as _tve, json as _jve
512
+ with open("debug-7c8974.log", "a") as _fve:
513
+ _fve.write(_jve.dumps({"sessionId":"7c8974","hypothesisId":"A","location":"isbn_catalog.py:verify_isbn_anchor","message":"anchor_exception","data":{"platform":platform_id,"anchor":anchor,"error":str(exc)[:200]},"timestamp":int(_tve.time()*1000)}) + "\n")
514
+ except Exception:
515
+ pass
516
+ # #endregion
517
  logger.debug(
518
  "ISBN anchor verify failed",
519
  platform=platform_id,
app/services/platform_presence.py CHANGED
@@ -754,6 +754,15 @@ def _finalize_listing_url(listing: PlatformListing) -> None:
754
  clean = rewritten
755
  except Exception:
756
  pass
 
 
 
 
 
 
 
 
 
757
  if not clean or classify_retailer_url(clean, pid) != "product":
758
  listing.listing_url = None
759
  listing.status = "not_found"
@@ -952,6 +961,16 @@ async def scan_platform_presence(
952
  author=snap.author or author,
953
  )
954
 
 
 
 
 
 
 
 
 
 
 
955
  if not snap.asin:
956
  resolved_asin = _extract_asin(scan_isbn or isbn)
957
  if not resolved_asin and gr_links.get("amazon"):
 
754
  clean = rewritten
755
  except Exception:
756
  pass
757
+ # #region agent log
758
+ _cls = classify_retailer_url(clean, pid) if clean else "none"
759
+ try:
760
+ import time as _t2, json as _j2
761
+ with open("debug-7c8974.log", "a") as _f2:
762
+ _f2.write(_j2.dumps({"sessionId":"7c8974","hypothesisId":"B","location":"platform_presence.py:_finalize","message":"finalize_url","data":{"pid":pid,"raw":listing.listing_url,"clean":clean,"cls":_cls},"timestamp":int(_t2.time()*1000)}) + "\n")
763
+ except Exception:
764
+ pass
765
+ # #endregion
766
  if not clean or classify_retailer_url(clean, pid) != "product":
767
  listing.listing_url = None
768
  listing.status = "not_found"
 
961
  author=snap.author or author,
962
  )
963
 
964
+ # #region agent log
965
+ import time as _time
966
+ try:
967
+ with open("debug-7c8974.log", "a") as _f:
968
+ import json as _j
969
+ _f.write(_j.dumps({"sessionId":"7c8974","hypothesisId":"A-D","location":"platform_presence.py:after_enrich","message":"retailer_links_after_enrich","data":{"links":{k:v for k,v in (snap.retailer_links or {}).items()}},"timestamp":int(_time.time()*1000)}) + "\n")
970
+ except Exception:
971
+ pass
972
+ # #endregion
973
+
974
  if not snap.asin:
975
  resolved_asin = _extract_asin(scan_isbn or isbn)
976
  if not resolved_asin and gr_links.get("amazon"):