Update Discord trade listings
This commit is contained in:
+33
-2
@@ -924,6 +924,8 @@ def normalize_fodder_units(value: str) -> str:
|
||||
|
||||
|
||||
def normalize_unit_names(value: str) -> str:
|
||||
value = re.sub(r"(?<!\w)×\s*(\d+)(?=\s+\w)", r"\1x", value)
|
||||
value = re.sub(r"\b(\d+)\s*×\s*(?=\w)", r"\1x ", value)
|
||||
value = re.sub(r"\bInfinity\s+Mage\s*/\s*Merlin\s+(Evo|Unevo)\b",
|
||||
lambda m: "Merlin " + m.group(1).capitalize(), value, flags=re.I)
|
||||
value = re.sub(r"\bShiny(?=Heathcliff\b)", "Shiny ", value, flags=re.I)
|
||||
@@ -1474,6 +1476,11 @@ def normalize_evo_status(value: str) -> str:
|
||||
def normalize_variant_quantities(value: str) -> str:
|
||||
"""Expand explicit inventory totals without losing their shiny or Evo status."""
|
||||
unit = UNIT_MENTION.pattern
|
||||
value = re.sub(
|
||||
rf"(?P<unit>{unit})\s+(?P<status>Evo|Unevo)\s+×(?P<count>\d+)\b",
|
||||
lambda m: f'{m.group("count")}x {m.group("unit")} {m.group("status")}',
|
||||
value, flags=re.I,
|
||||
)
|
||||
value = re.sub(r"\b3\s+Fodder\s+Units\s*\(\s*2\s+Unevo\s*,\s*1\s+Evo\s*\)",
|
||||
"2x Fodder Units Unevo | 1x Fodder Units Evo", value, flags=re.I)
|
||||
|
||||
@@ -1622,6 +1629,26 @@ def clean_offer_items(offer: str) -> str:
|
||||
return " | ".join(kept)
|
||||
|
||||
|
||||
def separate_received_bid(offer: str) -> tuple[str, str]:
|
||||
"""Keep an already received best/high offer out of owned inventory."""
|
||||
owned: list[str] = []
|
||||
bids: list[str] = []
|
||||
for raw in offer.split("|"):
|
||||
part = raw.strip()
|
||||
match = re.search(r"\b(?:BEST|HIGH)\s+OFFER\s*:?\s*", part, re.I)
|
||||
if match:
|
||||
if part[:match.start()].strip(" ,;:-"):
|
||||
owned.append(part[:match.start()].strip(" ,;:-"))
|
||||
bid = part[match.end():].strip(" ,;:-")
|
||||
if bid:
|
||||
bids.append(bid)
|
||||
continue
|
||||
part = re.sub(r"^PRE[-\s]?TRADE\s+", "", part, flags=re.I)
|
||||
if part:
|
||||
owned.append(part)
|
||||
return " | ".join(owned), " | ".join(bids)
|
||||
|
||||
|
||||
def clean_request_segments(value: str) -> str:
|
||||
"""Keep requested units and conditions, discarding clear UI/chat fragments."""
|
||||
kept = []
|
||||
@@ -2533,7 +2560,8 @@ def export_csv(conn: sqlite3.Connection, output: Path, detailed: bool) -> int:
|
||||
writer = csv.writer(stream)
|
||||
if detailed:
|
||||
writer.writerow(["offer", "looking_for", "lf", "mlf", "nlf",
|
||||
"author_hash", "reposts_seen", "updates_seen"])
|
||||
"author_hash", "reposts_seen", "updates_seen",
|
||||
"pretrade", "received_bid"])
|
||||
else:
|
||||
writer.writerow(["offer", "looking_for"])
|
||||
rows = conn.execute(
|
||||
@@ -2541,7 +2569,9 @@ def export_csv(conn: sqlite3.Connection, output: Path, detailed: bool) -> int:
|
||||
FROM trades ORDER BY id"""
|
||||
)
|
||||
for row in rows:
|
||||
pretrade = bool(re.search(r"\b(?:PRE|PRE[-\s]?TRADE)\b", row[0], re.I))
|
||||
offer = clean_offer_items(clean_export_text(row[0]))
|
||||
offer, received_bid = separate_received_bid(offer)
|
||||
if not offer:
|
||||
continue
|
||||
values = list(row)
|
||||
@@ -2569,6 +2599,7 @@ def export_csv(conn: sqlite3.Connection, output: Path, detailed: bool) -> int:
|
||||
offer = recover_explicit_my_offers(offer, values[2], values[3])
|
||||
offer = recover_partial_proposal_offers(offer, values[2], values[3])
|
||||
values[0] = offer
|
||||
values.extend(["yes" if pretrade else "", received_bid])
|
||||
export_values = values if detailed else values[:2]
|
||||
writer.writerow([excel_safe(v) if isinstance(v, str) else v for v in export_values])
|
||||
count += 1
|
||||
@@ -2580,7 +2611,7 @@ def export_csv(conn: sqlite3.Connection, output: Path, detailed: bool) -> int:
|
||||
"SELECT 1 FROM trades WHERE author_hash=? AND canon_offer=? LIMIT 1", key
|
||||
).fetchone()
|
||||
if (friend_offer and key not in emitted_friends and not already_stored):
|
||||
friend_values = [friend_offer, "", "", "", "", friend_hash, 1, 0]
|
||||
friend_values = [friend_offer, "", "", "", "", friend_hash, 1, 0, "", ""]
|
||||
writer.writerow([excel_safe(v) if isinstance(v, str) else v
|
||||
for v in (friend_values if detailed else friend_values[:2])])
|
||||
emitted_friends.add(key)
|
||||
|
||||
Reference in New Issue
Block a user