Muttered3 commited on
Commit
1b2a7fe
Β·
verified Β·
1 Parent(s): ebcc930

Update parser.py

Browse files
Files changed (1) hide show
  1. parser.py +29 -16
parser.py CHANGED
@@ -3,40 +3,53 @@ import re
3
  def parse_html(html: str, final_url: str, word: str) -> str:
4
  """
5
  High-Performance Text Boundary Token Mapper optimized for reading
6
- asynchronous AJAX responses with structural fallbacks.
7
  """
8
  if not html or not html.strip():
9
  return "AVAILABLE"
10
 
11
- # Flatten trailing breaks and tabs into clean space arrays
12
  clean_html = " ".join(html.split())
13
  word_clean = word.strip().replace("@", "").lower()
 
14
 
15
  # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
16
- # ENGINE 1: EXACT ROW PATTERN VALIDATION
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
18
  search_regex = re.compile(rf'>@{word_clean}<.*?class="[^"]*status[^"]*"[^>]*>\s*([^<]+?)\s*<', re.IGNORECASE)
19
  match = search_regex.search(clean_html)
20
 
21
  if match:
22
- status_text = match.group(1).strip().lower()
23
- if "auction" in status_text or "bidding" in status_text: return "ON_AUCTION"
24
- if "sold" in status_text: return "SOLD"
25
- if "unavailable" in status_text: return "UNAVAILABLE"
26
- if "taken" in status_text or "offer" in status_text: return "TAKEN"
27
- if "sale" in status_text or "purchase" in status_text: return "FOR_SALE"
28
- return status_text.upper()
29
 
30
- # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
31
- # ENGINE 2: GLOBAL TEXT BOUNDARY FALLBACK SCANS
32
- # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
33
  fallback_text = clean_html.lower()
34
-
35
  if "on auction" in fallback_text: return "ON_AUCTION"
36
  if "sold for" in fallback_text or "recently sold" in fallback_text: return "SOLD"
37
  if "taken" in fallback_text or "make an offer" in fallback_text: return "TAKEN"
38
  if "for sale" in fallback_text or "purchase" in fallback_text: return "FOR_SALE"
39
  if "unavailable" in fallback_text: return "UNAVAILABLE"
40
- if "available" in fallback_text: return "AVAILABLE"
41
 
42
- return "UNAVAILABLE"
 
3
  def parse_html(html: str, final_url: str, word: str) -> str:
4
  """
5
  High-Performance Text Boundary Token Mapper optimized for reading
6
+ direct username landing pages and search loops cleanly.
7
  """
8
  if not html or not html.strip():
9
  return "AVAILABLE"
10
 
11
+ # Flatten trailing breaks and spaces into clean strings
12
  clean_html = " ".join(html.split())
13
  word_clean = word.strip().replace("@", "").lower()
14
+ final_url_lower = final_url.lower()
15
 
16
  # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
17
+ # ENGINE 1: DIRECT DOM VIEW REACTION
18
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
19
+ if '/username/' in final_url_lower and '?query=' not in final_url_lower:
20
+ # Isolate class definitions safely without heavy BeautifulSoup dependency overhead
21
+ status_match = re.search(r'class="tm-section-header-status[^"]*"[^>]*>\s*([^<]+?)\s*</span>', clean_html, re.IGNORECASE)
22
+ if status_match:
23
+ s = status_match.group(1).strip().lower()
24
+ if "sold" in s: return "SOLD"
25
+ if "taken" in s: return "TAKEN"
26
+ if "auction" in s: return "ON_AUCTION"
27
+ if "available" in s: return "AVAILABLE"
28
+ if "sale" in s or "purchase" in s: return "FOR_SALE"
29
+
30
+ if 'is already taken' in clean_html.lower() or 'make an offer' in clean_html.lower():
31
+ return "TAKEN"
32
+
33
+ # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
34
+ # ENGINE 2: REDIRECTED SEARCH RESULTS TABLE ROW LOOKUP
35
  # ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
36
  search_regex = re.compile(rf'>@{word_clean}<.*?class="[^"]*status[^"]*"[^>]*>\s*([^<]+?)\s*<', re.IGNORECASE)
37
  match = search_regex.search(clean_html)
38
 
39
  if match:
40
+ s = match.group(1).strip().lower()
41
+ if "auction" in s or "bidding" in s: return "ON_AUCTION"
42
+ if "sold" in s: return "SOLD"
43
+ if "unavailable" in s: return "UNAVAILABLE"
44
+ if "taken" in s or "offer" in s: return "TAKEN"
45
+ if "sale" in s or "purchase" in s: return "FOR_SALE"
 
46
 
47
+ # Global text layout backup verification block scans
 
 
48
  fallback_text = clean_html.lower()
 
49
  if "on auction" in fallback_text: return "ON_AUCTION"
50
  if "sold for" in fallback_text or "recently sold" in fallback_text: return "SOLD"
51
  if "taken" in fallback_text or "make an offer" in fallback_text: return "TAKEN"
52
  if "for sale" in fallback_text or "purchase" in fallback_text: return "FOR_SALE"
53
  if "unavailable" in fallback_text: return "UNAVAILABLE"
 
54
 
55
+ return "AVAILABLE"