cleanup and fix runtime bugs
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
import json
|
||||
import random
|
||||
import re
|
||||
import time
|
||||
from pathlib import Path
|
||||
from typing import Any, Iterable
|
||||
|
||||
@@ -12,18 +10,6 @@ def save_to_json(data: Any, filename: str | Path) -> None:
|
||||
path.write_text(json.dumps(data, ensure_ascii=False, indent=2), encoding="utf-8")
|
||||
|
||||
|
||||
def short_sleep(a: float = 0.10, b: float = 0.35) -> None:
|
||||
time.sleep(random.uniform(a, b))
|
||||
|
||||
|
||||
def mask_email(email: str) -> str:
|
||||
if "@" not in email:
|
||||
return "***"
|
||||
local, domain = email.split("@", 1)
|
||||
safe_local = local[:2] + "***" if len(local) > 2 else local[:1] + "*"
|
||||
return f"{safe_local}@{domain}"
|
||||
|
||||
|
||||
def first_non_empty(values: Iterable[Any]) -> Any | None:
|
||||
for value in values:
|
||||
if value not in (None, "", [], {}, ()):
|
||||
@@ -38,6 +24,7 @@ PRICE_RE = re.compile(r"\$\s?([\d,]+(?:\.\d{1,2})?)")
|
||||
|
||||
|
||||
def deep_find_key(obj, target_keys: set[str], max_depth: int = 64, _depth: int = 0) -> list:
|
||||
# Рекурсивно ищет значения по набору ключей в произвольном JSON-дереве.
|
||||
found = []
|
||||
if _depth >= max_depth:
|
||||
return found
|
||||
|
||||
Reference in New Issue
Block a user