Spaces:
Sleeping
Sleeping
Update commercial_stats.py
Browse files- commercial_stats.py +7 -3
commercial_stats.py
CHANGED
|
@@ -1,4 +1,3 @@
|
|
| 1 |
-
# commercial_stats.py
|
| 2 |
import hashlib
|
| 3 |
import json
|
| 4 |
import os
|
|
@@ -21,9 +20,14 @@ router = APIRouter()
|
|
| 21 |
SCANCODE_CMD = os.environ.get("SCANCODE_CMD", "scancode") # must exist on PATH
|
| 22 |
HTTP_TIMEOUT = 15 # per-request timeout
|
| 23 |
HTTP_WORKERS = int(os.environ.get("COMM_HTTP_WORKERS", "10"))
|
| 24 |
-
BATCH_SIZE = int(os.environ.get("COMM_SCAN_BATCH", "
|
| 25 |
SAMPLE_CAP = 200
|
| 26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
# ---------------- in-memory state ----------------
|
| 28 |
_state_lock = threading.Lock()
|
| 29 |
_state: Dict[str, Any] = {
|
|
@@ -241,7 +245,7 @@ def _scan_thread():
|
|
| 241 |
# write each text as file "<hash>.txt"
|
| 242 |
for h in chunk:
|
| 243 |
with open(os.path.join(in_dir, f"{h}.txt"), "w", encoding="utf-8") as f:
|
| 244 |
-
f.write(text_hash_to_text[h])
|
| 245 |
|
| 246 |
# run scancode once over the directory
|
| 247 |
by_file = _run_scancode_dir(in_dir, out_json)
|
|
|
|
|
|
|
| 1 |
import hashlib
|
| 2 |
import json
|
| 3 |
import os
|
|
|
|
| 20 |
SCANCODE_CMD = os.environ.get("SCANCODE_CMD", "scancode") # must exist on PATH
|
| 21 |
HTTP_TIMEOUT = 15 # per-request timeout
|
| 22 |
HTTP_WORKERS = int(os.environ.get("COMM_HTTP_WORKERS", "10"))
|
| 23 |
+
BATCH_SIZE = int(os.environ.get("COMM_SCAN_BATCH", "50")) # reduced from 150
|
| 24 |
SAMPLE_CAP = 200
|
| 25 |
|
| 26 |
+
# ---------------- helpers ----------------
|
| 27 |
+
_TAG_RE = re.compile(r"<[^>]+>")
|
| 28 |
+
def _html_to_text(s: str) -> str:
|
| 29 |
+
return _TAG_RE.sub(" ", s).strip()
|
| 30 |
+
|
| 31 |
# ---------------- in-memory state ----------------
|
| 32 |
_state_lock = threading.Lock()
|
| 33 |
_state: Dict[str, Any] = {
|
|
|
|
| 245 |
# write each text as file "<hash>.txt"
|
| 246 |
for h in chunk:
|
| 247 |
with open(os.path.join(in_dir, f"{h}.txt"), "w", encoding="utf-8") as f:
|
| 248 |
+
f.write(_html_to_text(text_hash_to_text[h]))
|
| 249 |
|
| 250 |
# run scancode once over the directory
|
| 251 |
by_file = _run_scancode_dir(in_dir, out_json)
|