Datasets:
Moves files to sharded folders.
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- .gitignore +0 -1
- README.md +24 -6
- scripts/clubs/01_scrape.py +10 -3
- scripts/designs/01_scrape.py +35 -2
- scripts/flights/01_scrape.py +10 -3
- scripts/glossary/01_scrape.py +9 -2
- scripts/motors/01_scrape.py +10 -3
- scripts/parts/01_scrape.py +375 -0
- scripts/plans/01_scrape.py +9 -2
- scripts/products/01_scrape.py +10 -3
- scripts/reviews/01_scrape.py +10 -3
- source/clubs/detail/{000001.json → 000/000001.json} +0 -0
- source/clubs/detail/{000002.json → 000/000002.json} +0 -0
- source/clubs/detail/{000003.json → 000/000003.json} +0 -0
- source/clubs/detail/{000021.json → 000/000021.json} +0 -0
- source/clubs/detail/{000022.json → 000/000022.json} +0 -0
- source/clubs/detail/{000023.json → 000/000023.json} +0 -0
- source/clubs/detail/{000026.json → 000/000026.json} +0 -0
- source/clubs/detail/{000027.json → 000/000027.json} +0 -0
- source/clubs/detail/{000028.json → 000/000028.json} +0 -0
- source/clubs/detail/{000029.json → 000/000029.json} +0 -0
- source/clubs/detail/{000030.json → 000/000030.json} +0 -0
- source/clubs/detail/{000031.json → 000/000031.json} +0 -0
- source/clubs/detail/{000032.json → 000/000032.json} +0 -0
- source/clubs/detail/{000033.json → 000/000033.json} +0 -0
- source/clubs/detail/{000034.json → 000/000034.json} +0 -0
- source/clubs/detail/{000035.json → 000/000035.json} +0 -0
- source/clubs/detail/{000036.json → 000/000036.json} +0 -0
- source/clubs/detail/{000037.json → 000/000037.json} +0 -0
- source/clubs/detail/{000038.json → 000/000038.json} +0 -0
- source/clubs/detail/{000039.json → 000/000039.json} +0 -0
- source/clubs/detail/{000040.json → 000/000040.json} +0 -0
- source/clubs/detail/{000041.json → 000/000041.json} +0 -0
- source/clubs/detail/{000042.json → 000/000042.json} +0 -0
- source/clubs/detail/{000043.json → 000/000043.json} +0 -0
- source/clubs/detail/{000044.json → 000/000044.json} +0 -0
- source/clubs/detail/{000045.json → 000/000045.json} +0 -0
- source/clubs/detail/{000046.json → 000/000046.json} +0 -0
- source/clubs/detail/{000047.json → 000/000047.json} +0 -0
- source/clubs/detail/{000048.json → 000/000048.json} +0 -0
- source/clubs/detail/{000049.json → 000/000049.json} +0 -0
- source/clubs/detail/{000050.json → 000/000050.json} +0 -0
- source/clubs/detail/{000051.json → 000/000051.json} +0 -0
- source/clubs/detail/{000052.json → 000/000052.json} +0 -0
- source/clubs/detail/{000053.json → 000/000053.json} +0 -0
- source/clubs/detail/{000054.json → 000/000054.json} +0 -0
- source/clubs/detail/{000055.json → 000/000055.json} +0 -0
- source/clubs/detail/{000056.json → 000/000056.json} +0 -0
- source/clubs/detail/{000057.json → 000/000057.json} +0 -0
- source/clubs/detail/{000058.json → 000/000058.json} +0 -0
.gitignore
CHANGED
|
@@ -13,7 +13,6 @@ __pycache__/
|
|
| 13 |
dist/
|
| 14 |
build/
|
| 15 |
eggs/
|
| 16 |
-
parts/
|
| 17 |
var/
|
| 18 |
sdist/
|
| 19 |
wheels/
|
|
|
|
| 13 |
dist/
|
| 14 |
build/
|
| 15 |
eggs/
|
|
|
|
| 16 |
var/
|
| 17 |
sdist/
|
| 18 |
wheels/
|
README.md
CHANGED
|
@@ -46,29 +46,34 @@ Legend: `[ ]` not started · `[~]` in progress · `[x]` complete
|
|
| 46 |
source/
|
| 47 |
reviews/
|
| 48 |
index.jsonl
|
| 49 |
-
detail/{id}.json
|
| 50 |
products/
|
| 51 |
index.jsonl
|
| 52 |
-
detail/{id}.json
|
|
|
|
|
|
|
|
|
|
| 53 |
motors/
|
| 54 |
index.jsonl
|
| 55 |
-
detail/{id}.json
|
| 56 |
designs/
|
| 57 |
index.jsonl
|
| 58 |
-
detail/{id}.json
|
| 59 |
files/
|
| 60 |
ork/
|
| 61 |
rkt/
|
| 62 |
flights/
|
| 63 |
index.jsonl
|
| 64 |
-
detail/{id}.json
|
| 65 |
plans/
|
| 66 |
index.jsonl
|
|
|
|
| 67 |
clubs/
|
| 68 |
index.jsonl
|
|
|
|
| 69 |
glossary/
|
| 70 |
index.jsonl
|
| 71 |
-
detail/{slug}.json
|
| 72 |
manufacturers/
|
| 73 |
index.jsonl
|
| 74 |
designers/
|
|
@@ -84,3 +89,16 @@ source/
|
|
| 84 |
cp_library/
|
| 85 |
index.jsonl
|
| 86 |
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
source/
|
| 47 |
reviews/
|
| 48 |
index.jsonl
|
| 49 |
+
detail/{shard}/{id}.json
|
| 50 |
products/
|
| 51 |
index.jsonl
|
| 52 |
+
detail/{shard}/{id}.json
|
| 53 |
+
parts/
|
| 54 |
+
index.jsonl
|
| 55 |
+
detail/{shard}/{slug}.json
|
| 56 |
motors/
|
| 57 |
index.jsonl
|
| 58 |
+
detail/{shard}/{id}.json
|
| 59 |
designs/
|
| 60 |
index.jsonl
|
| 61 |
+
detail/{shard}/{id}.json
|
| 62 |
files/
|
| 63 |
ork/
|
| 64 |
rkt/
|
| 65 |
flights/
|
| 66 |
index.jsonl
|
| 67 |
+
detail/{shard}/{id}.json
|
| 68 |
plans/
|
| 69 |
index.jsonl
|
| 70 |
+
detail/{shard}/{slug}.json
|
| 71 |
clubs/
|
| 72 |
index.jsonl
|
| 73 |
+
detail/{shard}/{id}.json
|
| 74 |
glossary/
|
| 75 |
index.jsonl
|
| 76 |
+
detail/{shard}/{slug}.json
|
| 77 |
manufacturers/
|
| 78 |
index.jsonl
|
| 79 |
designers/
|
|
|
|
| 89 |
cp_library/
|
| 90 |
index.jsonl
|
| 91 |
```
|
| 92 |
+
ndex.jsonl
|
| 93 |
+
power_classes/
|
| 94 |
+
index.jsonl
|
| 95 |
+
cp_library/
|
| 96 |
+
index.jsonl
|
| 97 |
+
```
|
| 98 |
+
```
|
| 99 |
+
ndex.jsonl
|
| 100 |
+
power_classes/
|
| 101 |
+
index.jsonl
|
| 102 |
+
cp_library/
|
| 103 |
+
index.jsonl
|
| 104 |
+
```
|
scripts/clubs/01_scrape.py
CHANGED
|
@@ -249,8 +249,10 @@ def scrape_detail(
|
|
| 249 |
index_rec: dict,
|
| 250 |
force: bool = False,
|
| 251 |
) -> Optional[dict]:
|
| 252 |
-
club_id = index_rec["id"]
|
| 253 |
-
|
|
|
|
|
|
|
| 254 |
|
| 255 |
if dest.exists() and not force:
|
| 256 |
log.debug("Already scraped %s, skipping.", club_id)
|
|
@@ -331,7 +333,12 @@ def main() -> None:
|
|
| 331 |
skipped += 1
|
| 332 |
continue
|
| 333 |
|
| 334 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 335 |
try:
|
| 336 |
dest.write_text(
|
| 337 |
json.dumps(result, indent=2, ensure_ascii=False), encoding="utf-8"
|
|
|
|
| 249 |
index_rec: dict,
|
| 250 |
force: bool = False,
|
| 251 |
) -> Optional[dict]:
|
| 252 |
+
club_id = int(index_rec["id"])
|
| 253 |
+
shard = f"{club_id // 1000:03d}"
|
| 254 |
+
shard_dir = DETAIL_DIR / shard
|
| 255 |
+
dest = shard_dir / f"{club_id:06d}.json"
|
| 256 |
|
| 257 |
if dest.exists() and not force:
|
| 258 |
log.debug("Already scraped %s, skipping.", club_id)
|
|
|
|
| 333 |
skipped += 1
|
| 334 |
continue
|
| 335 |
|
| 336 |
+
club_id = int(rec["id"])
|
| 337 |
+
shard = f"{club_id // 1000:03d}"
|
| 338 |
+
shard_dir = DETAIL_DIR / shard
|
| 339 |
+
shard_dir.mkdir(parents=True, exist_ok=True)
|
| 340 |
+
dest = shard_dir / f"{club_id:06d}.json"
|
| 341 |
+
|
| 342 |
try:
|
| 343 |
dest.write_text(
|
| 344 |
json.dumps(result, indent=2, ensure_ascii=False), encoding="utf-8"
|
scripts/designs/01_scrape.py
CHANGED
|
@@ -167,6 +167,20 @@ def _extract_person(soup: BeautifulSoup, label: str) -> Optional[dict]:
|
|
| 167 |
|
| 168 |
return None
|
| 169 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 170 |
def _parse_detail(html: str, index_rec: dict, format_ext: str) -> dict:
|
| 171 |
soup = BeautifulSoup(html, "lxml")
|
| 172 |
|
|
@@ -210,6 +224,17 @@ def _parse_detail(html: str, index_rec: dict, format_ext: str) -> dict:
|
|
| 210 |
cp_loc, cp_from = _parse_measure(cp_raw)
|
| 211 |
margin_val, margin_status = _parse_margin(margin_raw)
|
| 212 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 213 |
design_id = int(index_rec["id"])
|
| 214 |
local_path = f"files/{format_ext}/{design_id:06d}.{format_ext}"
|
| 215 |
|
|
@@ -231,6 +256,7 @@ def _parse_detail(html: str, index_rec: dict, format_ext: str) -> dict:
|
|
| 231 |
"cp": {"location_in": cp_loc, "location_from": cp_from} if cp_loc is not None else None,
|
| 232 |
"margin": margin_val,
|
| 233 |
"margin_status": margin_status,
|
|
|
|
| 234 |
"file_url": file_url,
|
| 235 |
"external_url": external_url,
|
| 236 |
"local_path": local_path if file_url else None
|
|
@@ -285,7 +311,9 @@ def scrape_detail(
|
|
| 285 |
force: bool = False,
|
| 286 |
) -> Optional[dict]:
|
| 287 |
design_id = int(index_rec["id"])
|
| 288 |
-
|
|
|
|
|
|
|
| 289 |
format_ext = index_rec["_ext"]
|
| 290 |
dest_file = FILES_DIR / format_ext / f"{design_id:06d}.{format_ext}"
|
| 291 |
|
|
@@ -394,7 +422,12 @@ def main() -> None:
|
|
| 394 |
skipped += 1
|
| 395 |
continue
|
| 396 |
|
| 397 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 398 |
try:
|
| 399 |
dest.write_text(
|
| 400 |
json.dumps(result, indent=2, ensure_ascii=False), encoding="utf-8"
|
|
|
|
| 167 |
|
| 168 |
return None
|
| 169 |
|
| 170 |
+
def _slug_from_path(path: str) -> str:
|
| 171 |
+
"""
|
| 172 |
+
Extract the slug from a url path.
|
| 173 |
+
e.g. '/custom-18-aircraft-plywood-trapezoid-fin-set-3163.html' ->
|
| 174 |
+
'custom-18-aircraft-plywood-trapezoid-fin-set'
|
| 175 |
+
"""
|
| 176 |
+
name = path.lstrip("/").removesuffix(".html")
|
| 177 |
+
# Remove trailing -NNNNNNNNNNNN timestamp (12-digit numeric suffix) if any
|
| 178 |
+
name = re.sub(r"-\d{10,}$", "", name)
|
| 179 |
+
# Sometimes it's just a 4 digit ID suffix
|
| 180 |
+
name = re.sub(r"-\d{4,8}$", "", name)
|
| 181 |
+
return name
|
| 182 |
+
|
| 183 |
+
|
| 184 |
def _parse_detail(html: str, index_rec: dict, format_ext: str) -> dict:
|
| 185 |
soup = BeautifulSoup(html, "lxml")
|
| 186 |
|
|
|
|
| 224 |
cp_loc, cp_from = _parse_measure(cp_raw)
|
| 225 |
margin_val, margin_status = _parse_margin(margin_raw)
|
| 226 |
|
| 227 |
+
# Parts Breakdown
|
| 228 |
+
parts = []
|
| 229 |
+
parts_h4 = soup.find(['h4', 'h5'], string=re.compile(r'Parts Breakdown', re.I))
|
| 230 |
+
if parts_h4:
|
| 231 |
+
parts_list = parts_h4.find_next_sibling('ul')
|
| 232 |
+
if parts_list:
|
| 233 |
+
for a in parts_list.find_all('a'):
|
| 234 |
+
href = a.get('href')
|
| 235 |
+
if href:
|
| 236 |
+
parts.append(_slug_from_path(href))
|
| 237 |
+
|
| 238 |
design_id = int(index_rec["id"])
|
| 239 |
local_path = f"files/{format_ext}/{design_id:06d}.{format_ext}"
|
| 240 |
|
|
|
|
| 256 |
"cp": {"location_in": cp_loc, "location_from": cp_from} if cp_loc is not None else None,
|
| 257 |
"margin": margin_val,
|
| 258 |
"margin_status": margin_status,
|
| 259 |
+
"parts": parts,
|
| 260 |
"file_url": file_url,
|
| 261 |
"external_url": external_url,
|
| 262 |
"local_path": local_path if file_url else None
|
|
|
|
| 311 |
force: bool = False,
|
| 312 |
) -> Optional[dict]:
|
| 313 |
design_id = int(index_rec["id"])
|
| 314 |
+
shard = f"{design_id // 1000:03d}"
|
| 315 |
+
shard_dir = DETAIL_DIR / shard
|
| 316 |
+
dest_json = shard_dir / f"{design_id:06d}.json"
|
| 317 |
format_ext = index_rec["_ext"]
|
| 318 |
dest_file = FILES_DIR / format_ext / f"{design_id:06d}.{format_ext}"
|
| 319 |
|
|
|
|
| 422 |
skipped += 1
|
| 423 |
continue
|
| 424 |
|
| 425 |
+
design_id = int(rec["id"])
|
| 426 |
+
shard = f"{design_id // 1000:03d}"
|
| 427 |
+
shard_dir = DETAIL_DIR / shard
|
| 428 |
+
shard_dir.mkdir(parents=True, exist_ok=True)
|
| 429 |
+
dest = shard_dir / f"{design_id:06d}.json"
|
| 430 |
+
|
| 431 |
try:
|
| 432 |
dest.write_text(
|
| 433 |
json.dumps(result, indent=2, ensure_ascii=False), encoding="utf-8"
|
scripts/flights/01_scrape.py
CHANGED
|
@@ -284,8 +284,10 @@ def scrape_detail(
|
|
| 284 |
index_rec: dict,
|
| 285 |
force: bool = False,
|
| 286 |
) -> dict:
|
| 287 |
-
flight_id = index_rec["id"]
|
| 288 |
-
|
|
|
|
|
|
|
| 289 |
|
| 290 |
if dest.exists() and not force:
|
| 291 |
log.debug("Already scraped %s, skipping.", flight_id)
|
|
@@ -369,7 +371,12 @@ def main() -> None:
|
|
| 369 |
skipped += 1
|
| 370 |
continue
|
| 371 |
|
| 372 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 373 |
try:
|
| 374 |
dest.write_text(
|
| 375 |
json.dumps(result, indent=2, ensure_ascii=False), encoding="utf-8"
|
|
|
|
| 284 |
index_rec: dict,
|
| 285 |
force: bool = False,
|
| 286 |
) -> dict:
|
| 287 |
+
flight_id = int(index_rec["id"])
|
| 288 |
+
shard = f"{flight_id // 1000:03d}"
|
| 289 |
+
shard_dir = DETAIL_DIR / shard
|
| 290 |
+
dest = shard_dir / f"{flight_id:06d}.json"
|
| 291 |
|
| 292 |
if dest.exists() and not force:
|
| 293 |
log.debug("Already scraped %s, skipping.", flight_id)
|
|
|
|
| 371 |
skipped += 1
|
| 372 |
continue
|
| 373 |
|
| 374 |
+
flight_id = int(rec["id"])
|
| 375 |
+
shard = f"{flight_id // 1000:03d}"
|
| 376 |
+
shard_dir = DETAIL_DIR / shard
|
| 377 |
+
shard_dir.mkdir(parents=True, exist_ok=True)
|
| 378 |
+
dest = shard_dir / f"{flight_id:06d}.json"
|
| 379 |
+
|
| 380 |
try:
|
| 381 |
dest.write_text(
|
| 382 |
json.dumps(result, indent=2, ensure_ascii=False), encoding="utf-8"
|
scripts/glossary/01_scrape.py
CHANGED
|
@@ -194,7 +194,9 @@ def scrape_detail(
|
|
| 194 |
force: bool = False,
|
| 195 |
) -> Optional[dict]:
|
| 196 |
slug = index_rec["slug"]
|
| 197 |
-
|
|
|
|
|
|
|
| 198 |
|
| 199 |
if dest.exists() and not force:
|
| 200 |
log.debug("Already scraped %s, skipping.", slug)
|
|
@@ -273,7 +275,12 @@ def main() -> None:
|
|
| 273 |
skipped += 1
|
| 274 |
continue
|
| 275 |
|
| 276 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 277 |
try:
|
| 278 |
dest.write_text(
|
| 279 |
json.dumps(result, indent=2, ensure_ascii=False), encoding="utf-8"
|
|
|
|
| 194 |
force: bool = False,
|
| 195 |
) -> Optional[dict]:
|
| 196 |
slug = index_rec["slug"]
|
| 197 |
+
shard = slug[0].lower() if slug else "_"
|
| 198 |
+
shard_dir = DETAIL_DIR / shard
|
| 199 |
+
dest = shard_dir / f"{slug}.json"
|
| 200 |
|
| 201 |
if dest.exists() and not force:
|
| 202 |
log.debug("Already scraped %s, skipping.", slug)
|
|
|
|
| 275 |
skipped += 1
|
| 276 |
continue
|
| 277 |
|
| 278 |
+
slug = rec["slug"]
|
| 279 |
+
shard = slug[0].lower() if slug else "_"
|
| 280 |
+
shard_dir = DETAIL_DIR / shard
|
| 281 |
+
shard_dir.mkdir(parents=True, exist_ok=True)
|
| 282 |
+
dest = shard_dir / f"{slug}.json"
|
| 283 |
+
|
| 284 |
try:
|
| 285 |
dest.write_text(
|
| 286 |
json.dumps(result, indent=2, ensure_ascii=False), encoding="utf-8"
|
scripts/motors/01_scrape.py
CHANGED
|
@@ -290,8 +290,10 @@ def scrape_detail(
|
|
| 290 |
index_doc: dict,
|
| 291 |
force: bool = False,
|
| 292 |
) -> Optional[dict]:
|
| 293 |
-
motor_id = index_doc["id"]
|
| 294 |
-
|
|
|
|
|
|
|
| 295 |
|
| 296 |
if dest.exists() and not force:
|
| 297 |
log.debug("Already scraped %s, skipping.", motor_id)
|
|
@@ -371,7 +373,12 @@ def main() -> None:
|
|
| 371 |
skipped += 1
|
| 372 |
continue
|
| 373 |
|
| 374 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 375 |
try:
|
| 376 |
dest.write_text(
|
| 377 |
json.dumps(result, indent=2, ensure_ascii=False), encoding="utf-8"
|
|
|
|
| 290 |
index_doc: dict,
|
| 291 |
force: bool = False,
|
| 292 |
) -> Optional[dict]:
|
| 293 |
+
motor_id = int(index_doc["id"])
|
| 294 |
+
shard = f"{motor_id // 1000:03d}"
|
| 295 |
+
shard_dir = DETAIL_DIR / shard
|
| 296 |
+
dest = shard_dir / f"{motor_id:06d}.json"
|
| 297 |
|
| 298 |
if dest.exists() and not force:
|
| 299 |
log.debug("Already scraped %s, skipping.", motor_id)
|
|
|
|
| 373 |
skipped += 1
|
| 374 |
continue
|
| 375 |
|
| 376 |
+
motor_id = int(doc["id"])
|
| 377 |
+
shard = f"{motor_id // 1000:03d}"
|
| 378 |
+
shard_dir = DETAIL_DIR / shard
|
| 379 |
+
shard_dir.mkdir(parents=True, exist_ok=True)
|
| 380 |
+
dest = shard_dir / f"{motor_id:06d}.json"
|
| 381 |
+
|
| 382 |
try:
|
| 383 |
dest.write_text(
|
| 384 |
json.dumps(result, indent=2, ensure_ascii=False), encoding="utf-8"
|
scripts/parts/01_scrape.py
ADDED
|
@@ -0,0 +1,375 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
scrape_parts.py — Fetch the RocketReviews.com rocket parts database and scrape each
|
| 4 |
+
detail page, saving structured JSON to source/parts/.
|
| 5 |
+
|
| 6 |
+
Output
|
| 7 |
+
------
|
| 8 |
+
source/parts/index.jsonl one record per part (raw index fields)
|
| 9 |
+
source/parts/detail/{slug}.json full parsed detail per part
|
| 10 |
+
|
| 11 |
+
Usage
|
| 12 |
+
-----
|
| 13 |
+
python scripts/parts/01_scrape.py
|
| 14 |
+
python scripts/parts/01_scrape.py --delay 1.0 --limit 10
|
| 15 |
+
python scripts/parts/01_scrape.py --force # re-scrape existing files
|
| 16 |
+
"""
|
| 17 |
+
|
| 18 |
+
from __future__ import annotations
|
| 19 |
+
|
| 20 |
+
import argparse
|
| 21 |
+
import json
|
| 22 |
+
import logging
|
| 23 |
+
import re
|
| 24 |
+
import sys
|
| 25 |
+
import time
|
| 26 |
+
from datetime import datetime, timezone
|
| 27 |
+
from pathlib import Path
|
| 28 |
+
from typing import Optional
|
| 29 |
+
from urllib.parse import urljoin
|
| 30 |
+
|
| 31 |
+
import requests
|
| 32 |
+
from bs4 import BeautifulSoup
|
| 33 |
+
from requests.adapters import HTTPAdapter
|
| 34 |
+
from urllib3.util.retry import Retry
|
| 35 |
+
|
| 36 |
+
# ---------------------------------------------------------------------------
|
| 37 |
+
# Config
|
| 38 |
+
# ---------------------------------------------------------------------------
|
| 39 |
+
|
| 40 |
+
BASE_URL = "https://www.rocketreviews.com"
|
| 41 |
+
INDEX_URL = f"{BASE_URL}/index.php"
|
| 42 |
+
USER_AGENT = "RocketReviews-Dataset/1.0"
|
| 43 |
+
DEFAULT_DELAY = 1.0
|
| 44 |
+
|
| 45 |
+
CATEGORIES = [
|
| 46 |
+
"Body Tube", "Fin Set", "Launch Lug", "Nose Cone",
|
| 47 |
+
"Parachute", "Ring", "Streamer", "Transition", "Other"
|
| 48 |
+
]
|
| 49 |
+
|
| 50 |
+
ROOT = Path(__file__).parent.parent.parent
|
| 51 |
+
SOURCE_DIR = ROOT / "source" / "parts"
|
| 52 |
+
DETAIL_DIR = SOURCE_DIR / "detail"
|
| 53 |
+
|
| 54 |
+
# ---------------------------------------------------------------------------
|
| 55 |
+
# Logging
|
| 56 |
+
# ---------------------------------------------------------------------------
|
| 57 |
+
|
| 58 |
+
logging.basicConfig(
|
| 59 |
+
level=logging.INFO,
|
| 60 |
+
format="%(asctime)s %(levelname)s %(message)s",
|
| 61 |
+
handlers=[logging.StreamHandler(sys.stdout)],
|
| 62 |
+
)
|
| 63 |
+
log = logging.getLogger(__name__)
|
| 64 |
+
|
| 65 |
+
# ---------------------------------------------------------------------------
|
| 66 |
+
# HTTP session
|
| 67 |
+
# ---------------------------------------------------------------------------
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
def _build_session() -> requests.Session:
|
| 71 |
+
s = requests.Session()
|
| 72 |
+
s.headers["User-Agent"] = USER_AGENT
|
| 73 |
+
retry = Retry(
|
| 74 |
+
total=3,
|
| 75 |
+
backoff_factor=2.0,
|
| 76 |
+
status_forcelist=[429, 500, 502, 503, 504],
|
| 77 |
+
allowed_methods=["GET", "POST"],
|
| 78 |
+
)
|
| 79 |
+
s.mount("https://", HTTPAdapter(max_retries=retry))
|
| 80 |
+
s.mount("http://", HTTPAdapter(max_retries=retry))
|
| 81 |
+
return s
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
class RateLimiter:
|
| 85 |
+
def __init__(self, delay: float) -> None:
|
| 86 |
+
self.delay = delay
|
| 87 |
+
self._last: float = 0.0
|
| 88 |
+
|
| 89 |
+
def wait(self) -> None:
|
| 90 |
+
elapsed = time.monotonic() - self._last
|
| 91 |
+
if elapsed < self.delay:
|
| 92 |
+
time.sleep(self.delay - elapsed)
|
| 93 |
+
self._last = time.monotonic()
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
# ---------------------------------------------------------------------------
|
| 97 |
+
# Parsing helpers
|
| 98 |
+
# ---------------------------------------------------------------------------
|
| 99 |
+
|
| 100 |
+
def _normalize_string(val: Optional[str]) -> Optional[str]:
|
| 101 |
+
if not val:
|
| 102 |
+
return None
|
| 103 |
+
val = val.strip()
|
| 104 |
+
if val in ("-Unknown-", "-", "", "Unknown"):
|
| 105 |
+
return None
|
| 106 |
+
return val
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
def _slug_from_path(path: str) -> str:
|
| 110 |
+
"""
|
| 111 |
+
Extract the slug from a url path.
|
| 112 |
+
e.g. '/custom-18-aircraft-plywood-trapezoid-fin-set-3163.html' ->
|
| 113 |
+
'custom-18-aircraft-plywood-trapezoid-fin-set'
|
| 114 |
+
"""
|
| 115 |
+
name = path.lstrip("/").removesuffix(".html")
|
| 116 |
+
# Remove trailing -NNNNNNNNNNNN timestamp (12-digit numeric suffix) if any
|
| 117 |
+
name = re.sub(r"-\d{10,}$", "", name)
|
| 118 |
+
# Sometimes it's just a 4 digit ID suffix
|
| 119 |
+
name = re.sub(r"-\d{4,8}$", "", name)
|
| 120 |
+
return name
|
| 121 |
+
|
| 122 |
+
|
| 123 |
+
def _parse_detail(html: str, index_rec: dict) -> dict:
|
| 124 |
+
"""Merge index-level fields with full detail page information."""
|
| 125 |
+
soup = BeautifulSoup(html, "lxml")
|
| 126 |
+
|
| 127 |
+
data = {
|
| 128 |
+
**index_rec,
|
| 129 |
+
"scraped_at": datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ"),
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
# Try to grab a better title from the h1/h2 tags
|
| 133 |
+
h_tags = soup.find_all(['h1', 'h2', 'h3'])
|
| 134 |
+
found_title = None
|
| 135 |
+
for h in h_tags:
|
| 136 |
+
text = h.get_text(strip=True)
|
| 137 |
+
if text and "RocketReviews.com" not in text and text != "Rocket Parts Database":
|
| 138 |
+
# Remove the 'Rocketry Parts Database >> Category >>' breadcrumb prefix if it exists
|
| 139 |
+
text = re.sub(r"^.*>>\s*", "", text)
|
| 140 |
+
found_title = _normalize_string(text)
|
| 141 |
+
break
|
| 142 |
+
|
| 143 |
+
if found_title:
|
| 144 |
+
data["title"] = found_title
|
| 145 |
+
|
| 146 |
+
data["manufacturer_url"] = None
|
| 147 |
+
data["related_designs"] = []
|
| 148 |
+
|
| 149 |
+
# Parse the table data
|
| 150 |
+
tables = soup.find_all('table')
|
| 151 |
+
for t in tables:
|
| 152 |
+
for row in t.find_all('tr'):
|
| 153 |
+
cells = row.find_all(['td', 'th'])
|
| 154 |
+
# Many property tables are 2 columns (Key, Value) but some might have an image in the 1st col
|
| 155 |
+
if len(cells) >= 2:
|
| 156 |
+
key_node = cells[-2].find(['b', 'strong'])
|
| 157 |
+
if not key_node:
|
| 158 |
+
# sometimes the key is just plain text in the left column
|
| 159 |
+
key_raw = cells[-2].get_text(strip=True).replace(':', '').strip()
|
| 160 |
+
else:
|
| 161 |
+
key_raw = key_node.get_text(strip=True).replace(':', '').strip()
|
| 162 |
+
|
| 163 |
+
val_cell = cells[-1]
|
| 164 |
+
val_raw = val_cell.get_text(separator=' ', strip=True).strip()
|
| 165 |
+
|
| 166 |
+
if key_raw and val_raw:
|
| 167 |
+
if "Download" in val_raw or not val_raw or val_raw == key_raw:
|
| 168 |
+
continue
|
| 169 |
+
|
| 170 |
+
if key_raw == "Manufacturer":
|
| 171 |
+
a_tag = val_cell.find('a')
|
| 172 |
+
if a_tag and a_tag.get('href'):
|
| 173 |
+
href = a_tag['href']
|
| 174 |
+
data["manufacturer_url"] = href if href.startswith("http") else urljoin(BASE_URL, href)
|
| 175 |
+
|
| 176 |
+
if key_raw == "Related Designs":
|
| 177 |
+
for a in val_cell.find_all('a'):
|
| 178 |
+
href = a.get('href')
|
| 179 |
+
if href:
|
| 180 |
+
data["related_designs"].append({
|
| 181 |
+
"name": a.get_text(strip=True),
|
| 182 |
+
"url": href if href.startswith("http") else urljoin(BASE_URL, href),
|
| 183 |
+
"slug": _slug_from_path(href)
|
| 184 |
+
})
|
| 185 |
+
continue
|
| 186 |
+
|
| 187 |
+
key_clean = key_raw.lower().replace(' ', '_').replace('/', '_')
|
| 188 |
+
data[key_clean] = _normalize_string(val_raw)
|
| 189 |
+
|
| 190 |
+
return data
|
| 191 |
+
|
| 192 |
+
|
| 193 |
+
# ---------------------------------------------------------------------------
|
| 194 |
+
# Fetch helpers
|
| 195 |
+
# ---------------------------------------------------------------------------
|
| 196 |
+
|
| 197 |
+
def fetch_category_index(session: requests.Session, category: str, rate: RateLimiter) -> list[dict]:
|
| 198 |
+
"""Fetch all parts for a specific category."""
|
| 199 |
+
log.info("Fetching index for category: %s", category)
|
| 200 |
+
rate.wait()
|
| 201 |
+
|
| 202 |
+
# POST to get redirect to the category's parts page
|
| 203 |
+
post_data = {'action': 'parts', 'autoredir': 'true', 'category': category}
|
| 204 |
+
resp = session.post(INDEX_URL, data=post_data, timeout=30)
|
| 205 |
+
resp.raise_for_status()
|
| 206 |
+
|
| 207 |
+
soup = BeautifulSoup(resp.text, 'lxml')
|
| 208 |
+
records = []
|
| 209 |
+
|
| 210 |
+
tables = soup.find_all('table')
|
| 211 |
+
# The parts table is usually the second table on the page
|
| 212 |
+
table = None
|
| 213 |
+
for t in tables:
|
| 214 |
+
if t.find('th') or (t.find('tr') and 'Title' in t.find('tr').get_text()):
|
| 215 |
+
table = t
|
| 216 |
+
break
|
| 217 |
+
|
| 218 |
+
if not table:
|
| 219 |
+
log.warning("Could not find the data table for category: %s", category)
|
| 220 |
+
return records
|
| 221 |
+
|
| 222 |
+
for row in table.find_all('tr')[1:]:
|
| 223 |
+
cells = row.find_all(['td', 'th'])
|
| 224 |
+
if not cells:
|
| 225 |
+
continue
|
| 226 |
+
|
| 227 |
+
a_tag = row.find('a')
|
| 228 |
+
if not a_tag or not a_tag.get('href'):
|
| 229 |
+
continue
|
| 230 |
+
|
| 231 |
+
href = a_tag['href']
|
| 232 |
+
detail_url = href if href.startswith("http") else urljoin(BASE_URL, href)
|
| 233 |
+
slug = _slug_from_path(href)
|
| 234 |
+
|
| 235 |
+
# In the index we just save the basic identifiers and title. The full metadata
|
| 236 |
+
# (dimensions, materials, etc) will be scraped from the detail page
|
| 237 |
+
# because the index table columns vary wildly by category.
|
| 238 |
+
|
| 239 |
+
# The first cell usually contains the title string
|
| 240 |
+
title = _normalize_string(cells[0].get_text(strip=True))
|
| 241 |
+
|
| 242 |
+
records.append({
|
| 243 |
+
"slug": slug,
|
| 244 |
+
"category": category,
|
| 245 |
+
"title": title,
|
| 246 |
+
"url": detail_url
|
| 247 |
+
})
|
| 248 |
+
|
| 249 |
+
log.info("Category '%s' returned %d records.", category, len(records))
|
| 250 |
+
return records
|
| 251 |
+
|
| 252 |
+
|
| 253 |
+
def scrape_detail(
|
| 254 |
+
session: requests.Session,
|
| 255 |
+
rate: RateLimiter,
|
| 256 |
+
index_rec: dict,
|
| 257 |
+
force: bool = False,
|
| 258 |
+
) -> Optional[dict]:
|
| 259 |
+
slug = index_rec["slug"]
|
| 260 |
+
shard = slug[0].lower() if slug else "_"
|
| 261 |
+
shard_dir = DETAIL_DIR / shard
|
| 262 |
+
dest = shard_dir / f"{slug}.json"
|
| 263 |
+
|
| 264 |
+
if dest.exists() and not force:
|
| 265 |
+
log.debug("Already scraped %s, skipping.", slug)
|
| 266 |
+
return None
|
| 267 |
+
|
| 268 |
+
url = index_rec["url"]
|
| 269 |
+
rate.wait()
|
| 270 |
+
|
| 271 |
+
try:
|
| 272 |
+
resp = session.get(url, timeout=30)
|
| 273 |
+
resp.raise_for_status()
|
| 274 |
+
except requests.RequestException as exc:
|
| 275 |
+
log.warning("Failed to fetch part %s: %s", slug, exc)
|
| 276 |
+
return None
|
| 277 |
+
|
| 278 |
+
return _parse_detail(resp.text, index_rec)
|
| 279 |
+
|
| 280 |
+
|
| 281 |
+
# ---------------------------------------------------------------------------
|
| 282 |
+
# Main
|
| 283 |
+
# ---------------------------------------------------------------------------
|
| 284 |
+
|
| 285 |
+
|
| 286 |
+
def main() -> None:
|
| 287 |
+
parser = argparse.ArgumentParser(description="Scrape RocketReviews.com parts database.")
|
| 288 |
+
parser.add_argument(
|
| 289 |
+
"--delay",
|
| 290 |
+
type=float,
|
| 291 |
+
default=DEFAULT_DELAY,
|
| 292 |
+
help=f"Seconds between requests (default: {DEFAULT_DELAY})",
|
| 293 |
+
)
|
| 294 |
+
parser.add_argument(
|
| 295 |
+
"--limit",
|
| 296 |
+
type=int,
|
| 297 |
+
default=None,
|
| 298 |
+
help="Stop after scraping this many detail pages (useful for testing)",
|
| 299 |
+
)
|
| 300 |
+
parser.add_argument(
|
| 301 |
+
"--force",
|
| 302 |
+
action="store_true",
|
| 303 |
+
help="Re-scrape parts that already have a saved detail file",
|
| 304 |
+
)
|
| 305 |
+
args = parser.parse_args()
|
| 306 |
+
|
| 307 |
+
SOURCE_DIR.mkdir(parents=True, exist_ok=True)
|
| 308 |
+
DETAIL_DIR.mkdir(parents=True, exist_ok=True)
|
| 309 |
+
|
| 310 |
+
session = _build_session()
|
| 311 |
+
rate = RateLimiter(args.delay)
|
| 312 |
+
|
| 313 |
+
# ------------------------------------------------------------------
|
| 314 |
+
# Step 1: fetch indexes for all categories
|
| 315 |
+
# ------------------------------------------------------------------
|
| 316 |
+
all_records = []
|
| 317 |
+
|
| 318 |
+
for category in CATEGORIES:
|
| 319 |
+
records = fetch_category_index(session, category, rate)
|
| 320 |
+
all_records.extend(records)
|
| 321 |
+
|
| 322 |
+
scraped_at = datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%SZ")
|
| 323 |
+
index_path = SOURCE_DIR / "index.jsonl"
|
| 324 |
+
with index_path.open("w", encoding="utf-8") as f:
|
| 325 |
+
for rec in all_records:
|
| 326 |
+
f.write(json.dumps({**rec, "scraped_at": scraped_at}) + "\n")
|
| 327 |
+
log.info("Wrote %d total index records to %s", len(all_records), index_path)
|
| 328 |
+
|
| 329 |
+
# ------------------------------------------------------------------
|
| 330 |
+
# Step 2: scrape each detail page
|
| 331 |
+
# ------------------------------------------------------------------
|
| 332 |
+
if args.limit:
|
| 333 |
+
all_records = all_records[: args.limit]
|
| 334 |
+
|
| 335 |
+
ok = skipped = failed = 0
|
| 336 |
+
total = len(all_records)
|
| 337 |
+
|
| 338 |
+
for i, rec in enumerate(all_records, 1):
|
| 339 |
+
result = scrape_detail(session, rate, rec, force=args.force)
|
| 340 |
+
|
| 341 |
+
if result is None:
|
| 342 |
+
skipped += 1
|
| 343 |
+
continue
|
| 344 |
+
|
| 345 |
+
slug = rec["slug"]
|
| 346 |
+
shard = slug[0].lower() if slug else "_"
|
| 347 |
+
shard_dir = DETAIL_DIR / shard
|
| 348 |
+
shard_dir.mkdir(parents=True, exist_ok=True)
|
| 349 |
+
dest = shard_dir / f"{slug}.json"
|
| 350 |
+
|
| 351 |
+
try:
|
| 352 |
+
dest.write_text(
|
| 353 |
+
json.dumps(result, indent=2, ensure_ascii=False), encoding="utf-8"
|
| 354 |
+
)
|
| 355 |
+
ok += 1
|
| 356 |
+
log.debug("Saved %s", dest.name)
|
| 357 |
+
except OSError as exc:
|
| 358 |
+
log.warning("Could not write %s: %s", dest, exc)
|
| 359 |
+
failed += 1
|
| 360 |
+
|
| 361 |
+
if i % 25 == 0 or i == total:
|
| 362 |
+
log.info(
|
| 363 |
+
"Progress: %d/%d — ok=%d skipped=%d failed=%d",
|
| 364 |
+
i,
|
| 365 |
+
total,
|
| 366 |
+
ok,
|
| 367 |
+
skipped,
|
| 368 |
+
failed,
|
| 369 |
+
)
|
| 370 |
+
|
| 371 |
+
log.info("Done — ok=%d skipped=%d failed=%d", ok, skipped, failed)
|
| 372 |
+
|
| 373 |
+
|
| 374 |
+
if __name__ == "__main__":
|
| 375 |
+
main()
|
scripts/plans/01_scrape.py
CHANGED
|
@@ -213,7 +213,9 @@ def scrape_detail(
|
|
| 213 |
force: bool = False,
|
| 214 |
) -> Optional[dict]:
|
| 215 |
slug = index_rec["slug"]
|
| 216 |
-
|
|
|
|
|
|
|
| 217 |
|
| 218 |
if dest.exists() and not force:
|
| 219 |
log.debug("Already scraped %s, skipping.", slug)
|
|
@@ -296,7 +298,12 @@ def main() -> None:
|
|
| 296 |
skipped += 1
|
| 297 |
continue
|
| 298 |
|
| 299 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 300 |
try:
|
| 301 |
dest.write_text(
|
| 302 |
json.dumps(result, indent=2, ensure_ascii=False), encoding="utf-8"
|
|
|
|
| 213 |
force: bool = False,
|
| 214 |
) -> Optional[dict]:
|
| 215 |
slug = index_rec["slug"]
|
| 216 |
+
shard = slug[0].lower() if slug else "_"
|
| 217 |
+
shard_dir = DETAIL_DIR / shard
|
| 218 |
+
dest = shard_dir / f"{slug}.json"
|
| 219 |
|
| 220 |
if dest.exists() and not force:
|
| 221 |
log.debug("Already scraped %s, skipping.", slug)
|
|
|
|
| 298 |
skipped += 1
|
| 299 |
continue
|
| 300 |
|
| 301 |
+
slug = rec["slug"]
|
| 302 |
+
shard = slug[0].lower() if slug else "_"
|
| 303 |
+
shard_dir = DETAIL_DIR / shard
|
| 304 |
+
shard_dir.mkdir(parents=True, exist_ok=True)
|
| 305 |
+
dest = shard_dir / f"{slug}.json"
|
| 306 |
+
|
| 307 |
try:
|
| 308 |
dest.write_text(
|
| 309 |
json.dumps(result, indent=2, ensure_ascii=False), encoding="utf-8"
|
scripts/products/01_scrape.py
CHANGED
|
@@ -300,8 +300,10 @@ def scrape_detail(
|
|
| 300 |
index_rec: dict,
|
| 301 |
force: bool = False,
|
| 302 |
) -> Optional[dict]:
|
| 303 |
-
product_id = index_rec["id"]
|
| 304 |
-
|
|
|
|
|
|
|
| 305 |
|
| 306 |
if dest.exists() and not force:
|
| 307 |
log.debug("Already scraped %s, skipping.", product_id)
|
|
@@ -381,7 +383,12 @@ def main() -> None:
|
|
| 381 |
skipped += 1
|
| 382 |
continue
|
| 383 |
|
| 384 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 385 |
try:
|
| 386 |
dest.write_text(
|
| 387 |
json.dumps(result, indent=2, ensure_ascii=False), encoding="utf-8"
|
|
|
|
| 300 |
index_rec: dict,
|
| 301 |
force: bool = False,
|
| 302 |
) -> Optional[dict]:
|
| 303 |
+
product_id = int(index_rec["id"])
|
| 304 |
+
shard = f"{product_id // 1000:03d}"
|
| 305 |
+
shard_dir = DETAIL_DIR / shard
|
| 306 |
+
dest = shard_dir / f"{product_id:06d}.json"
|
| 307 |
|
| 308 |
if dest.exists() and not force:
|
| 309 |
log.debug("Already scraped %s, skipping.", product_id)
|
|
|
|
| 383 |
skipped += 1
|
| 384 |
continue
|
| 385 |
|
| 386 |
+
product_id = int(rec["id"])
|
| 387 |
+
shard = f"{product_id // 1000:03d}"
|
| 388 |
+
shard_dir = DETAIL_DIR / shard
|
| 389 |
+
shard_dir.mkdir(parents=True, exist_ok=True)
|
| 390 |
+
dest = shard_dir / f"{product_id:06d}.json"
|
| 391 |
+
|
| 392 |
try:
|
| 393 |
dest.write_text(
|
| 394 |
json.dumps(result, indent=2, ensure_ascii=False), encoding="utf-8"
|
scripts/reviews/01_scrape.py
CHANGED
|
@@ -277,8 +277,10 @@ def scrape_detail(
|
|
| 277 |
index_rec: dict,
|
| 278 |
force: bool = False,
|
| 279 |
) -> Optional[dict]:
|
| 280 |
-
review_id = index_rec["id"]
|
| 281 |
-
|
|
|
|
|
|
|
| 282 |
|
| 283 |
if dest.exists() and not force:
|
| 284 |
log.debug("Already scraped %s, skipping.", review_id)
|
|
@@ -363,7 +365,12 @@ def main() -> None:
|
|
| 363 |
skipped += 1
|
| 364 |
continue
|
| 365 |
|
| 366 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 367 |
try:
|
| 368 |
dest.write_text(
|
| 369 |
json.dumps(result, indent=2, ensure_ascii=False), encoding="utf-8"
|
|
|
|
| 277 |
index_rec: dict,
|
| 278 |
force: bool = False,
|
| 279 |
) -> Optional[dict]:
|
| 280 |
+
review_id = int(index_rec["id"])
|
| 281 |
+
shard = f"{review_id // 1000:03d}"
|
| 282 |
+
shard_dir = DETAIL_DIR / shard
|
| 283 |
+
dest = shard_dir / f"{review_id:06d}.json"
|
| 284 |
|
| 285 |
if dest.exists() and not force:
|
| 286 |
log.debug("Already scraped %s, skipping.", review_id)
|
|
|
|
| 365 |
skipped += 1
|
| 366 |
continue
|
| 367 |
|
| 368 |
+
review_id = int(rec["id"])
|
| 369 |
+
shard = f"{review_id // 1000:03d}"
|
| 370 |
+
shard_dir = DETAIL_DIR / shard
|
| 371 |
+
shard_dir.mkdir(parents=True, exist_ok=True)
|
| 372 |
+
dest = shard_dir / f"{review_id:06d}.json"
|
| 373 |
+
|
| 374 |
try:
|
| 375 |
dest.write_text(
|
| 376 |
json.dumps(result, indent=2, ensure_ascii=False), encoding="utf-8"
|
source/clubs/detail/{000001.json → 000/000001.json}
RENAMED
|
File without changes
|
source/clubs/detail/{000002.json → 000/000002.json}
RENAMED
|
File without changes
|
source/clubs/detail/{000003.json → 000/000003.json}
RENAMED
|
File without changes
|
source/clubs/detail/{000021.json → 000/000021.json}
RENAMED
|
File without changes
|
source/clubs/detail/{000022.json → 000/000022.json}
RENAMED
|
File without changes
|
source/clubs/detail/{000023.json → 000/000023.json}
RENAMED
|
File without changes
|
source/clubs/detail/{000026.json → 000/000026.json}
RENAMED
|
File without changes
|
source/clubs/detail/{000027.json → 000/000027.json}
RENAMED
|
File without changes
|
source/clubs/detail/{000028.json → 000/000028.json}
RENAMED
|
File without changes
|
source/clubs/detail/{000029.json → 000/000029.json}
RENAMED
|
File without changes
|
source/clubs/detail/{000030.json → 000/000030.json}
RENAMED
|
File without changes
|
source/clubs/detail/{000031.json → 000/000031.json}
RENAMED
|
File without changes
|
source/clubs/detail/{000032.json → 000/000032.json}
RENAMED
|
File without changes
|
source/clubs/detail/{000033.json → 000/000033.json}
RENAMED
|
File without changes
|
source/clubs/detail/{000034.json → 000/000034.json}
RENAMED
|
File without changes
|
source/clubs/detail/{000035.json → 000/000035.json}
RENAMED
|
File without changes
|
source/clubs/detail/{000036.json → 000/000036.json}
RENAMED
|
File without changes
|
source/clubs/detail/{000037.json → 000/000037.json}
RENAMED
|
File without changes
|
source/clubs/detail/{000038.json → 000/000038.json}
RENAMED
|
File without changes
|
source/clubs/detail/{000039.json → 000/000039.json}
RENAMED
|
File without changes
|
source/clubs/detail/{000040.json → 000/000040.json}
RENAMED
|
File without changes
|
source/clubs/detail/{000041.json → 000/000041.json}
RENAMED
|
File without changes
|
source/clubs/detail/{000042.json → 000/000042.json}
RENAMED
|
File without changes
|
source/clubs/detail/{000043.json → 000/000043.json}
RENAMED
|
File without changes
|
source/clubs/detail/{000044.json → 000/000044.json}
RENAMED
|
File without changes
|
source/clubs/detail/{000045.json → 000/000045.json}
RENAMED
|
File without changes
|
source/clubs/detail/{000046.json → 000/000046.json}
RENAMED
|
File without changes
|
source/clubs/detail/{000047.json → 000/000047.json}
RENAMED
|
File without changes
|
source/clubs/detail/{000048.json → 000/000048.json}
RENAMED
|
File without changes
|
source/clubs/detail/{000049.json → 000/000049.json}
RENAMED
|
File without changes
|
source/clubs/detail/{000050.json → 000/000050.json}
RENAMED
|
File without changes
|
source/clubs/detail/{000051.json → 000/000051.json}
RENAMED
|
File without changes
|
source/clubs/detail/{000052.json → 000/000052.json}
RENAMED
|
File without changes
|
source/clubs/detail/{000053.json → 000/000053.json}
RENAMED
|
File without changes
|
source/clubs/detail/{000054.json → 000/000054.json}
RENAMED
|
File without changes
|
source/clubs/detail/{000055.json → 000/000055.json}
RENAMED
|
File without changes
|
source/clubs/detail/{000056.json → 000/000056.json}
RENAMED
|
File without changes
|
source/clubs/detail/{000057.json → 000/000057.json}
RENAMED
|
File without changes
|
source/clubs/detail/{000058.json → 000/000058.json}
RENAMED
|
File without changes
|