Monorepo: consolidate 7 repos into one
Combines shared, blog, market, cart, events, federation, and account into a single repository. Eliminates submodule sync, sibling model copying at build time, and per-app CI orchestration. Changes: - Remove per-app .git, .gitmodules, .gitea, submodule shared/ dirs - Remove stale sibling model copies from each app - Update all 6 Dockerfiles for monorepo build context (root = .) - Add build directives to docker-compose.yml - Add single .gitea/workflows/ci.yml with change detection - Add .dockerignore for monorepo build context - Create __init__.py for federation and account (cross-app imports)
This commit is contained in:
42
market/scrape/product/helpers/price.py
Normal file
42
market/scrape/product/helpers/price.py
Normal file
@@ -0,0 +1,42 @@
|
||||
|
||||
from __future__ import annotations
|
||||
import re
|
||||
from typing import Optional, Tuple
|
||||
|
||||
def parse_price(text: str) -> Tuple[Optional[float], Optional[str], str]:
|
||||
"""
|
||||
Return (value, currency, raw) from a price-like string.
|
||||
Supports symbols £, €, $; strips thousands commas.
|
||||
"""
|
||||
raw = (text or "").strip()
|
||||
m = re.search(r'([£€$])?\s*([0-9][0-9.,]*)', raw)
|
||||
if not m:
|
||||
return None, None, raw
|
||||
sym = m.group(1) or ""
|
||||
num = m.group(2).replace(",", "")
|
||||
try:
|
||||
value = float(num)
|
||||
except ValueError:
|
||||
return None, None, raw
|
||||
currency = {"£": "GBP", "€": "EUR", "$": "USD"}.get(sym, None)
|
||||
return value, currency, raw
|
||||
|
||||
def parse_case_size(text: str) -> Tuple[Optional[int], Optional[float], Optional[str], str]:
|
||||
"""
|
||||
Parse strings like "6 x 500g", "12x1L", "24 × 330 ml"
|
||||
Returns (count, item_qty, item_unit, raw)
|
||||
"""
|
||||
raw = (text or "").strip()
|
||||
if not raw:
|
||||
return None, None, None, raw
|
||||
t = re.sub(r"[×Xx]\s*", " x ", raw)
|
||||
m = re.search(r"(\d+)\s*x\s*([0-9]*\.?[0-9]+)\s*([a-zA-Z]+)", t)
|
||||
if not m:
|
||||
return None, None, None, raw
|
||||
count = int(m.group(1))
|
||||
try:
|
||||
item_qty = float(m.group(2))
|
||||
except ValueError:
|
||||
item_qty = None
|
||||
unit = m.group(3)
|
||||
return count, item_qty, unit, raw
|
||||
Reference in New Issue
Block a user