fix: review findings - OUTPUT_DIR centralised, no hardcoded vwts.ru, normal imports
This commit is contained in:
@@ -8,10 +8,8 @@
|
||||
"""
|
||||
|
||||
import sys, logging
|
||||
from pathlib import Path
|
||||
from .config import OUTPUT_DIR
|
||||
|
||||
# Настройка логирования
|
||||
OUTPUT_DIR = Path("vwts_data")
|
||||
OUTPUT_DIR.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
logging.basicConfig(
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,10 +1,12 @@
|
||||
"""Константы."""
|
||||
|
||||
import socket
|
||||
from pathlib import Path
|
||||
|
||||
# Глобальный таймаут сокетов
|
||||
socket.setdefaulttimeout(30)
|
||||
|
||||
OUTPUT_DIR = Path("vwts_data") # куда сохраняем данные
|
||||
DELAY = 1.5 # секунд между запросами
|
||||
TIMEOUT = (10, 30) # (connect, read)
|
||||
TOPICS_PER_FILE = 100
|
||||
|
||||
@@ -2,10 +2,8 @@
|
||||
|
||||
import json, logging
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
from .config import TOPICS_PER_FILE
|
||||
from .config import TOPICS_PER_FILE, OUTPUT_DIR
|
||||
|
||||
OUTPUT_DIR = Path("vwts_data")
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
|
||||
+7
-4
@@ -1,7 +1,9 @@
|
||||
"""Основной цикл: обход страниц раздела → темы → посты → сохранение."""
|
||||
|
||||
import sys, logging
|
||||
from .config import HEADERS
|
||||
from pathlib import Path
|
||||
from urllib.parse import urlparse
|
||||
from .config import OUTPUT_DIR
|
||||
from .fetch import get, session
|
||||
from .paginate import count, verify_last
|
||||
from .parse import parse_topics, parse_posts, parse_tags
|
||||
@@ -85,11 +87,13 @@ def run(section_url: str):
|
||||
posts, tags = [], parse_tags(topic_soup)
|
||||
|
||||
# ── Обход страниц темы ────────────────────────────────────
|
||||
base = f"{urlparse(section_url).scheme}://{urlparse(section_url).netloc}"
|
||||
|
||||
for tpp in range(1, topic_pages + 1):
|
||||
if tpp == 1:
|
||||
posts += parse_posts(topic_soup)
|
||||
else:
|
||||
tp2 = get(f"https://vwts.ru/forum/topic/{tid}/page-{tpp}")
|
||||
tp2 = get(f"{base}/forum/topic/{tid}/page-{tpp}")
|
||||
if tp2:
|
||||
posts += parse_posts(tp2)
|
||||
|
||||
@@ -106,7 +110,6 @@ def run(section_url: str):
|
||||
log.info("=" * 60)
|
||||
log.info(f"✅ '{section_name}' — {st['topic_count']} тем "
|
||||
f"в {st['file_index']+1} частях")
|
||||
for f in sorted((__import__('pathlib').Path('vwts_data') /
|
||||
section_slug).glob("part_*.jsonl")):
|
||||
for f in sorted((OUTPUT_DIR / section_slug).glob("part_*.jsonl")):
|
||||
log.info(f" 📄 {f.name} ({f.stat().st_size/1024/1024:.1f} MB)")
|
||||
log.info("=" * 60)
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
"""Управление состоянием (state.json в папке раздела)."""
|
||||
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
OUTPUT_DIR = Path("vwts_data")
|
||||
from .config import OUTPUT_DIR
|
||||
|
||||
|
||||
def _state_file(section_slug: str) -> Path:
|
||||
|
||||
Reference in New Issue
Block a user