modified: amazon/__pycache__/approve.cpython-39.pyc
modified: amazon/__pycache__/main.cpython-39.pyc modified: amazon/__pycache__/match_action.cpython-39.pyc new file: amazon/__pycache__/price_match.cpython-39.pyc modified: amazon/__pycache__/tool.cpython-39.pyc modified: amazon/approve.py new file: amazon/asin_status.py modified: amazon/main.py modified: amazon/price_match.py new file: "amazon/price_match_\346\227\247.py" modified: amazon/tool.py modified: assets/convert.js modified: assets/dedupe.js modified: assets/delete-brand.js modified: assets/split.js modified: new_web_source/convert.html modified: new_web_source/dedupe.html modified: new_web_source/delete-brand.html modified: new_web_source/split.html deleted: web_source/admin.html deleted: "web_source/brand - \345\211\257\346\234\254.html" deleted: "web_source/brand-\346\227\247.html" deleted: web_source/brand.html deleted: web_source/home.html deleted: web_source/index.html deleted: web_source/login.html
This commit is contained in:
@@ -7,6 +7,7 @@ except ImportError:
|
||||
|
||||
import requests
|
||||
from urllib.parse import quote
|
||||
import re
|
||||
|
||||
|
||||
def show_notification(message: str, message_type: str = "error"):
|
||||
@@ -112,5 +113,50 @@ def get_shop_info(shop_name: str, base_url: str = "http://8.136.19.173:18080") -
|
||||
|
||||
|
||||
|
||||
def remove_special_characters(text: str) -> str:
|
||||
"""
|
||||
去除字符串中的特殊字符,只保留数字、小数点和负号。
|
||||
例如:'£24.55' -> '24.55'
|
||||
"""
|
||||
# 匹配所有允许的字符:数字、小数点、负号
|
||||
# 注意:负号必须位于开头才合法,但这里只做字符保留,不做格式校验
|
||||
cleaned = re.sub(r'[^0-9.-]', '', text)
|
||||
return cleaned
|
||||
|
||||
|
||||
|
||||
def split_currency_values(currency_str: str) -> tuple[float, float]:
|
||||
"""
|
||||
将包含两个货币值的字符串拆分成两个浮点数。
|
||||
参数:
|
||||
currency_str (str): 格式如 "€22.64 + €0.00" 的字符串,中间以 '+' 分隔,
|
||||
每部分可包含任意货币符号或前缀/后缀。
|
||||
返回:
|
||||
tuple[float, float]: 两个数值,顺序与字符串中的出现顺序一致。
|
||||
异常:
|
||||
ValueError: 如果字符串不包含正好两个部分,或者任一部分中无法提取到数值。
|
||||
"""
|
||||
# 按第一个 '+' 分割,最多分为两部分
|
||||
parts = currency_str.split('+', 1)
|
||||
if len(parts) != 2:
|
||||
raise ValueError("字符串必须包含两个由 '+' 分隔的部分")
|
||||
|
||||
# 匹配整数或浮点数(可选负号)
|
||||
number_pattern = r'-?\d+(?:\.\d+)?'
|
||||
values = []
|
||||
|
||||
for part in parts:
|
||||
# 去除首尾空格
|
||||
part = part.strip()
|
||||
match = re.search(number_pattern, part)
|
||||
if not match:
|
||||
raise ValueError(f"无法从 '{part}' 中提取数值")
|
||||
values.append(float(match.group()))
|
||||
|
||||
return tuple(values)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
cu_str = "€58.44 + €0.00 匹配"
|
||||
res = split_currency_values(cu_str)
|
||||
print(sum(res))
|
||||
Reference in New Issue
Block a user