Rescue local-only reddit data: batch 3 (23 files)
Browse files- .gitattributes +5 -0
- reddit/_rescue_20260917/raw/r_PictureGame_posts.jsonl +3 -0
- reddit/_rescue_20260917/raw/r_whereisthis_comments.jsonl +3 -0
- reddit/_rescue_20260917/raw/r_whereisthis_posts.jsonl +3 -0
- reddit/_rescue_20260917/raw/scripts/rebase_canonical_paths.py +82 -0
- reddit/_rescue_20260917/raw/scripts/rebuild_canonical_names_from_associations.py +122 -0
- reddit/_rescue_20260917/raw/scripts/recover_reddit_image_associations.py +163 -0
- reddit/_rescue_20260917/raw/scripts/resume_reddit_upload_after_rate_limit.ps1 +51 -0
- reddit/_rescue_20260917/raw/scripts/retry_circuit_skipped.py +113 -0
- reddit/_rescue_20260917/raw/scripts/retry_failed_after_completion.py +123 -0
- reddit/_rescue_20260917/raw/scripts/retry_failed_images.py +328 -0
- reddit/_rescue_20260917/raw/scripts/retry_recoverable_284.py +118 -0
- reddit/_rescue_20260917/raw/scripts/run_canonical_reddit_upload.ps1 +51 -0
- reddit/_rescue_20260917/raw/scripts/start_picturegame.ps1 +19 -0
- reddit/_rescue_20260917/raw/scripts/start_retry_failed.ps1 +20 -0
- reddit/_rescue_20260917/raw/scripts/test_upload_canonical_reddit_images.py +130 -0
- reddit/_rescue_20260917/raw/scripts/upload_reddit_images_batched.py +1012 -0
- reddit/_rescue_20260917/raw/scripts/upload_reddit_images_large_folder.py +163 -0
- reddit/_rescue_20260917/raw/scripts/validate_canonical_reddit_metadata.py +233 -0
- reddit/_rescue_20260917/raw/solved_whereisthis/download.log +297 -0
- reddit/_rescue_20260917/raw/solved_whereisthis/download_state.json +1 -0
- reddit/_rescue_20260917/raw/solved_whereisthis/image_manifest.jsonl +0 -0
- reddit/_rescue_20260917/raw/solved_whereisthis/solved_comments.jsonl +3 -0
- reddit/_rescue_20260917/raw/solved_whereisthis/solved_posts_with_comments.jsonl +3 -0
.gitattributes
CHANGED
|
@@ -7061,3 +7061,8 @@ reddit/_rescue_20260917/nonimage/whereisthis/posts_with_comments.jsonl filter=lf
|
|
| 7061 |
reddit/_rescue_20260917/raw/r_GeoPuzzle_comments.jsonl filter=lfs diff=lfs merge=lfs -text
|
| 7062 |
reddit/_rescue_20260917/raw/r_GeoPuzzle_posts.jsonl filter=lfs diff=lfs merge=lfs -text
|
| 7063 |
reddit/_rescue_20260917/raw/r_PictureGame_comments.jsonl filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7061 |
reddit/_rescue_20260917/raw/r_GeoPuzzle_comments.jsonl filter=lfs diff=lfs merge=lfs -text
|
| 7062 |
reddit/_rescue_20260917/raw/r_GeoPuzzle_posts.jsonl filter=lfs diff=lfs merge=lfs -text
|
| 7063 |
reddit/_rescue_20260917/raw/r_PictureGame_comments.jsonl filter=lfs diff=lfs merge=lfs -text
|
| 7064 |
+
reddit/_rescue_20260917/raw/r_PictureGame_posts.jsonl filter=lfs diff=lfs merge=lfs -text
|
| 7065 |
+
reddit/_rescue_20260917/raw/r_whereisthis_comments.jsonl filter=lfs diff=lfs merge=lfs -text
|
| 7066 |
+
reddit/_rescue_20260917/raw/r_whereisthis_posts.jsonl filter=lfs diff=lfs merge=lfs -text
|
| 7067 |
+
reddit/_rescue_20260917/raw/solved_whereisthis/solved_comments.jsonl filter=lfs diff=lfs merge=lfs -text
|
| 7068 |
+
reddit/_rescue_20260917/raw/solved_whereisthis/solved_posts_with_comments.jsonl filter=lfs diff=lfs merge=lfs -text
|
reddit/_rescue_20260917/raw/r_PictureGame_posts.jsonl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:35cf14778d210953e13c5b6f1011063aad8551de0a48d30bceb79d04d45e8ede
|
| 3 |
+
size 507715312
|
reddit/_rescue_20260917/raw/r_whereisthis_comments.jsonl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d8da1e85b27237debbd6475e28426fef7fd0c3289a50d71222a94ab234d05334
|
| 3 |
+
size 360490554
|
reddit/_rescue_20260917/raw/r_whereisthis_posts.jsonl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:34e3fe20184410bd93a59d4ea834392938b4b7ffdb803b45c7c23bbdec3d9f36
|
| 3 |
+
size 151490892
|
reddit/_rescue_20260917/raw/scripts/rebase_canonical_paths.py
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Move derived canonical paths into a separate directory namespace."""
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
import argparse
|
| 6 |
+
import json
|
| 7 |
+
import re
|
| 8 |
+
from pathlib import Path
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
PATH_RE = re.compile(r"^reddit/images/(whereisthis|GeoPuzzle|PictureGame)/(\d{4})/(.+)$")
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def rebase(path: str | None) -> str | None:
|
| 15 |
+
if not path:
|
| 16 |
+
return path
|
| 17 |
+
match = PATH_RE.match(path)
|
| 18 |
+
if not match:
|
| 19 |
+
return path
|
| 20 |
+
return f"reddit/images/{match.group(1)}/canonical/{match.group(2)}/{match.group(3)}"
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def jsonl(path: Path):
|
| 24 |
+
with path.open("r", encoding="utf-8") as handle:
|
| 25 |
+
for line in handle:
|
| 26 |
+
if line.strip():
|
| 27 |
+
yield json.loads(line)
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
def transform(value):
|
| 31 |
+
if isinstance(value, dict):
|
| 32 |
+
result = {key: transform(item) for key, item in value.items()}
|
| 33 |
+
for key in ("canonical_path", "remote_path"):
|
| 34 |
+
if key in result and isinstance(result[key], str):
|
| 35 |
+
result[key] = rebase(result[key])
|
| 36 |
+
return result
|
| 37 |
+
if isinstance(value, list):
|
| 38 |
+
return [transform(item) for item in value]
|
| 39 |
+
if isinstance(value, str):
|
| 40 |
+
return PATH_RE.sub(lambda m: f"reddit/images/{m.group(1)}/canonical/{m.group(2)}/{m.group(3)}", value)
|
| 41 |
+
return value
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
def main() -> int:
|
| 45 |
+
parser = argparse.ArgumentParser()
|
| 46 |
+
parser.add_argument("--source-map", type=Path, required=True)
|
| 47 |
+
parser.add_argument("--source-bundle", type=Path, required=True)
|
| 48 |
+
parser.add_argument("--output-map", type=Path, required=True)
|
| 49 |
+
parser.add_argument("--output-bundle", type=Path, required=True)
|
| 50 |
+
args = parser.parse_args()
|
| 51 |
+
|
| 52 |
+
args.output_map.parent.mkdir(parents=True, exist_ok=True)
|
| 53 |
+
with args.output_map.open("w", encoding="utf-8", newline="\n") as out:
|
| 54 |
+
for row in jsonl(args.source_map):
|
| 55 |
+
out.write(json.dumps(transform(row), ensure_ascii=False, separators=(",", ":")) + "\n")
|
| 56 |
+
|
| 57 |
+
source = args.source_bundle / "reddit"
|
| 58 |
+
output = args.output_bundle / "reddit"
|
| 59 |
+
in_place = source.resolve() == output.resolve()
|
| 60 |
+
for path in source.rglob("*.jsonl"):
|
| 61 |
+
destination = path if in_place else output / path.relative_to(source)
|
| 62 |
+
destination.parent.mkdir(parents=True, exist_ok=True)
|
| 63 |
+
temp = destination.with_suffix(destination.suffix + ".part")
|
| 64 |
+
with path.open("r", encoding="utf-8") as src, temp.open("w", encoding="utf-8", newline="\n") as dst:
|
| 65 |
+
for line in src:
|
| 66 |
+
if line.strip():
|
| 67 |
+
dst.write(json.dumps(transform(json.loads(line)), ensure_ascii=False, separators=(",", ":")) + "\n")
|
| 68 |
+
else:
|
| 69 |
+
dst.write(line)
|
| 70 |
+
temp.replace(destination)
|
| 71 |
+
for path in source.rglob("*.json"):
|
| 72 |
+
destination = path if in_place else output / path.relative_to(source)
|
| 73 |
+
destination.parent.mkdir(parents=True, exist_ok=True)
|
| 74 |
+
if path.name not in {"canonical_migration_report.json", "canonical_validation_report.json"}:
|
| 75 |
+
destination.write_bytes(path.read_bytes())
|
| 76 |
+
|
| 77 |
+
print(json.dumps({"status": "passed", "source_map": str(args.source_map), "output_map": str(args.output_map), "output_bundle": str(args.output_bundle)}, ensure_ascii=False), flush=True)
|
| 78 |
+
return 0
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
if __name__ == "__main__":
|
| 82 |
+
raise SystemExit(main())
|
reddit/_rescue_20260917/raw/scripts/rebuild_canonical_names_from_associations.py
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Rebuild canonical image names from the fully recovered associations."""
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
import argparse
|
| 6 |
+
import json
|
| 7 |
+
import time
|
| 8 |
+
from collections import Counter, defaultdict
|
| 9 |
+
from pathlib import Path
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def jsonl(path: Path):
|
| 13 |
+
with path.open("r", encoding="utf-8") as handle:
|
| 14 |
+
for number, line in enumerate(handle, 1):
|
| 15 |
+
if line.strip():
|
| 16 |
+
try:
|
| 17 |
+
yield json.loads(line)
|
| 18 |
+
except json.JSONDecodeError as exc:
|
| 19 |
+
raise ValueError(f"invalid JSON: {path}:{number}") from exc
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def main() -> int:
|
| 23 |
+
parser = argparse.ArgumentParser()
|
| 24 |
+
parser.add_argument("--inventory", type=Path, required=True)
|
| 25 |
+
parser.add_argument("--associations", type=Path, required=True)
|
| 26 |
+
parser.add_argument("--old-naming-map", type=Path, required=True)
|
| 27 |
+
parser.add_argument("--output-root", type=Path, required=True)
|
| 28 |
+
parser.add_argument("--namespace", default="")
|
| 29 |
+
args = parser.parse_args()
|
| 30 |
+
started = time.time()
|
| 31 |
+
args.output_root.mkdir(parents=True, exist_ok=True)
|
| 32 |
+
|
| 33 |
+
inventory = {(x["community"], x["filename"]): x for x in jsonl(args.inventory)}
|
| 34 |
+
associations = {(x["community"], x["filename"]): x for x in jsonl(args.associations)}
|
| 35 |
+
old_names = {(x["community"], x["old_filename"]): x for x in jsonl(args.old_naming_map)}
|
| 36 |
+
if len(inventory) != 225307 or set(inventory) != set(associations) or set(inventory) != set(old_names):
|
| 37 |
+
raise RuntimeError("inventory, association, and old naming keys do not match")
|
| 38 |
+
|
| 39 |
+
grouped = defaultdict(list)
|
| 40 |
+
missing_post_id = []
|
| 41 |
+
for key, inv in inventory.items():
|
| 42 |
+
assoc = associations[key]
|
| 43 |
+
refs = assoc.get("references", [])
|
| 44 |
+
direct = sorted({
|
| 45 |
+
str(x.get("post_id") or "").strip() for x in refs
|
| 46 |
+
if x.get("owner_type") == "post"
|
| 47 |
+
and str(x.get("owner_id") or "").strip() == str(x.get("post_id") or "").strip()
|
| 48 |
+
and str(x.get("post_id") or "").strip()
|
| 49 |
+
})
|
| 50 |
+
post_ids = sorted({str(x).strip() for x in assoc.get("post_ids", []) if str(x).strip()})
|
| 51 |
+
if not (direct or post_ids):
|
| 52 |
+
missing_post_id.append({"community": key[0], "filename": key[1]})
|
| 53 |
+
continue
|
| 54 |
+
post_id = (direct or post_ids)[0]
|
| 55 |
+
grouped[(key[0], post_id)].append((key, inv, assoc, old_names[key]))
|
| 56 |
+
if missing_post_id:
|
| 57 |
+
(args.output_root / "missing_post_ids.json").write_text(json.dumps(missing_post_id, ensure_ascii=False, indent=2), encoding="utf-8")
|
| 58 |
+
raise RuntimeError(f"images without post id: {len(missing_post_id)}")
|
| 59 |
+
|
| 60 |
+
mappings = []
|
| 61 |
+
name_counts = Counter()
|
| 62 |
+
changed_paths = 0
|
| 63 |
+
for (community, post_id), items in sorted(grouped.items()):
|
| 64 |
+
items.sort(key=lambda x: x[0][1])
|
| 65 |
+
width = max(3, len(str(len(items))))
|
| 66 |
+
for sequence, (key, inv, assoc, old) in enumerate(items, 1):
|
| 67 |
+
extension = Path(key[1]).suffix.lower()
|
| 68 |
+
sha = old["sha256"]
|
| 69 |
+
new_filename = f"{community}_{post_id}_{sequence:0{width}d}_{sha[:8]}{extension}"
|
| 70 |
+
shard = int(inv.get("shard", 0))
|
| 71 |
+
namespace = f"{args.namespace.strip('/')}/" if args.namespace.strip("/") else ""
|
| 72 |
+
new_path = f"reddit/images/{community}/{namespace}{shard:04d}/{new_filename}"
|
| 73 |
+
name_counts[(community, new_filename)] += 1
|
| 74 |
+
changed_paths += new_path != old["new_remote_path"]
|
| 75 |
+
mappings.append({
|
| 76 |
+
"community": community,
|
| 77 |
+
"old_filename": key[1],
|
| 78 |
+
"old_remote_path": inv["relative_path"],
|
| 79 |
+
"legacy_remote_path": inv["legacy_relative_path"],
|
| 80 |
+
"local_path": old["local_path"],
|
| 81 |
+
"size": int(inv["size"]),
|
| 82 |
+
"sha256": sha,
|
| 83 |
+
"canonical_post_id": post_id,
|
| 84 |
+
"sequence": sequence,
|
| 85 |
+
"association_count": int(assoc["association_count"]),
|
| 86 |
+
"associations": assoc.get("references", []),
|
| 87 |
+
"new_filename": new_filename,
|
| 88 |
+
"new_remote_path": new_path,
|
| 89 |
+
})
|
| 90 |
+
|
| 91 |
+
collisions = [
|
| 92 |
+
{"community": key[0], "new_filename": key[1], "count": count}
|
| 93 |
+
for key, count in name_counts.items() if count > 1
|
| 94 |
+
]
|
| 95 |
+
if collisions:
|
| 96 |
+
(args.output_root / "canonical_name_collisions.json").write_text(json.dumps(collisions, ensure_ascii=False, indent=2), encoding="utf-8")
|
| 97 |
+
raise RuntimeError(f"canonical name collisions: {len(collisions)}")
|
| 98 |
+
output = args.output_root / "canonical_image_mapping.jsonl"
|
| 99 |
+
with output.open("w", encoding="utf-8", newline="\n") as handle:
|
| 100 |
+
for row in sorted(mappings, key=lambda x: (x["community"], x["old_filename"])):
|
| 101 |
+
handle.write(json.dumps(row, ensure_ascii=False, separators=(",", ":")) + "\n")
|
| 102 |
+
report = {
|
| 103 |
+
"status": "passed",
|
| 104 |
+
"created_at": time.time(),
|
| 105 |
+
"elapsed_seconds": round(time.time() - started, 2),
|
| 106 |
+
"inventory_records": len(inventory),
|
| 107 |
+
"mapping_records": len(mappings),
|
| 108 |
+
"images_without_post_id": 0,
|
| 109 |
+
"canonical_name_collisions": 0,
|
| 110 |
+
"paths_changed_from_old_audit": changed_paths,
|
| 111 |
+
"contains_unlinked_name": any("_unlinked_" in x["new_filename"] for x in mappings),
|
| 112 |
+
"namespace": args.namespace.strip("/"),
|
| 113 |
+
"source_images_modified": False,
|
| 114 |
+
"remote_modified": False,
|
| 115 |
+
}
|
| 116 |
+
(args.output_root / "canonical_mapping_summary.json").write_text(json.dumps(report, ensure_ascii=False, indent=2), encoding="utf-8")
|
| 117 |
+
print(json.dumps(report, ensure_ascii=False), flush=True)
|
| 118 |
+
return 0
|
| 119 |
+
|
| 120 |
+
|
| 121 |
+
if __name__ == "__main__":
|
| 122 |
+
raise SystemExit(main())
|
reddit/_rescue_20260917/raw/scripts/recover_reddit_image_associations.py
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Recover image-to-post/comment associations from raw Reddit records.
|
| 2 |
+
|
| 3 |
+
Read-only: no source image, post JSONL, bundle, or remote repository is changed.
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
from __future__ import annotations
|
| 7 |
+
|
| 8 |
+
import argparse
|
| 9 |
+
import json
|
| 10 |
+
import time
|
| 11 |
+
from collections import Counter, defaultdict
|
| 12 |
+
from pathlib import Path
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
COMMUNITIES = ("whereisthis", "GeoPuzzle", "PictureGame")
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
def jsonl(path: Path):
|
| 19 |
+
if not path.exists():
|
| 20 |
+
return
|
| 21 |
+
with path.open("r", encoding="utf-8") as handle:
|
| 22 |
+
for number, line in enumerate(handle, 1):
|
| 23 |
+
if line.strip():
|
| 24 |
+
try:
|
| 25 |
+
yield json.loads(line)
|
| 26 |
+
except json.JSONDecodeError as exc:
|
| 27 |
+
raise ValueError(f"Invalid JSON: {path}:{number}") from exc
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
def filename_from_local(value) -> str | None:
|
| 31 |
+
if not isinstance(value, str) or not value:
|
| 32 |
+
return None
|
| 33 |
+
return Path(value.replace("\\", "/")).name
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
def main() -> int:
|
| 37 |
+
parser = argparse.ArgumentParser()
|
| 38 |
+
parser.add_argument("--inventory", type=Path, required=True)
|
| 39 |
+
parser.add_argument("--raw-root", type=Path, required=True)
|
| 40 |
+
parser.add_argument("--overflow-root", type=Path)
|
| 41 |
+
parser.add_argument("--bundle-root", type=Path)
|
| 42 |
+
parser.add_argument("--output-root", type=Path, required=True)
|
| 43 |
+
args = parser.parse_args()
|
| 44 |
+
started = time.time()
|
| 45 |
+
args.output_root.mkdir(parents=True, exist_ok=True)
|
| 46 |
+
|
| 47 |
+
inventory = list(jsonl(args.inventory) or ())
|
| 48 |
+
inventory_keys = {(r["community"], r["filename"]): r for r in inventory}
|
| 49 |
+
refs: dict[tuple[str, str], dict[tuple, dict]] = defaultdict(dict)
|
| 50 |
+
source_counts = Counter()
|
| 51 |
+
raw_rows = 0
|
| 52 |
+
raw_missing_local = 0
|
| 53 |
+
raw_not_inventory = 0
|
| 54 |
+
|
| 55 |
+
def add_record(community: str, record: dict, source: str) -> None:
|
| 56 |
+
nonlocal raw_rows, raw_missing_local, raw_not_inventory
|
| 57 |
+
raw_rows += 1
|
| 58 |
+
filename = filename_from_local(record.get("local_path"))
|
| 59 |
+
if not filename:
|
| 60 |
+
raw_missing_local += 1
|
| 61 |
+
return
|
| 62 |
+
key = (community, filename)
|
| 63 |
+
if key not in inventory_keys:
|
| 64 |
+
raw_not_inventory += 1
|
| 65 |
+
return
|
| 66 |
+
association = {
|
| 67 |
+
"post_id": str(record.get("post_id") or "").strip(),
|
| 68 |
+
"owner_type": str(record.get("owner_type") or "").strip(),
|
| 69 |
+
"owner_id": str(record.get("owner_id") or "").strip(),
|
| 70 |
+
"url": record.get("url"),
|
| 71 |
+
"status": record.get("status"),
|
| 72 |
+
"bytes": record.get("bytes"),
|
| 73 |
+
"source": source,
|
| 74 |
+
}
|
| 75 |
+
key2 = tuple(association.get(k) for k in ("post_id", "owner_type", "owner_id", "url"))
|
| 76 |
+
existing = refs[key].get(key2)
|
| 77 |
+
if existing:
|
| 78 |
+
sources = set(existing.get("sources", []))
|
| 79 |
+
sources.add(source)
|
| 80 |
+
existing["sources"] = sorted(sources)
|
| 81 |
+
else:
|
| 82 |
+
association["sources"] = [source]
|
| 83 |
+
refs[key][key2] = association
|
| 84 |
+
source_counts[source] += 1
|
| 85 |
+
|
| 86 |
+
raw_roots = [args.raw_root]
|
| 87 |
+
if args.overflow_root:
|
| 88 |
+
raw_roots.append(args.overflow_root)
|
| 89 |
+
for community in COMMUNITIES:
|
| 90 |
+
for raw_root in raw_roots:
|
| 91 |
+
community_root = raw_root / community
|
| 92 |
+
for path in sorted(community_root.glob("retry_state.jsonl")):
|
| 93 |
+
for record in jsonl(path) or ():
|
| 94 |
+
add_record(community, record, f"{raw_root.name}/retry_state.jsonl")
|
| 95 |
+
for path in sorted(community_root.glob("image_manifest*.jsonl")):
|
| 96 |
+
source = f"{raw_root.name}/{path.name}"
|
| 97 |
+
for record in jsonl(path) or ():
|
| 98 |
+
add_record(community, record, source)
|
| 99 |
+
|
| 100 |
+
if args.bundle_root:
|
| 101 |
+
bundle_manifest_root = args.bundle_root / "image_manifests"
|
| 102 |
+
for path in sorted(bundle_manifest_root.rglob("*.jsonl")):
|
| 103 |
+
community = path.parent.name
|
| 104 |
+
if community not in COMMUNITIES:
|
| 105 |
+
continue
|
| 106 |
+
for record in jsonl(path) or ():
|
| 107 |
+
add_record(community, record, f"bundle/{community}/{path.name}")
|
| 108 |
+
|
| 109 |
+
recovered = []
|
| 110 |
+
unresolved = []
|
| 111 |
+
ambiguous = []
|
| 112 |
+
for record in inventory:
|
| 113 |
+
key = (record["community"], record["filename"])
|
| 114 |
+
associations = sorted(
|
| 115 |
+
refs.get(key, {}).values(),
|
| 116 |
+
key=lambda x: (x["post_id"], x["owner_type"], x["owner_id"], x["url"] or "", x["source"]),
|
| 117 |
+
)
|
| 118 |
+
post_ids = sorted({x["post_id"] for x in associations if x["post_id"]})
|
| 119 |
+
output = {
|
| 120 |
+
"community": record["community"],
|
| 121 |
+
"filename": record["filename"],
|
| 122 |
+
"relative_path": record["relative_path"],
|
| 123 |
+
"legacy_relative_path": record["legacy_relative_path"],
|
| 124 |
+
"sha256": record.get("sha256"),
|
| 125 |
+
"size": record["size"],
|
| 126 |
+
"post_ids": post_ids,
|
| 127 |
+
"references": associations,
|
| 128 |
+
"association_count": len(associations),
|
| 129 |
+
"association_status": "recovered" if associations else "unresolved",
|
| 130 |
+
}
|
| 131 |
+
recovered.append(output)
|
| 132 |
+
if not associations:
|
| 133 |
+
unresolved.append(output)
|
| 134 |
+
if len(post_ids) > 1:
|
| 135 |
+
ambiguous.append(output)
|
| 136 |
+
|
| 137 |
+
association_path = args.output_root / "association_recovery.jsonl"
|
| 138 |
+
with association_path.open("w", encoding="utf-8") as handle:
|
| 139 |
+
for record in recovered:
|
| 140 |
+
handle.write(json.dumps(record, ensure_ascii=False, separators=(",", ":")) + "\n")
|
| 141 |
+
for name, records in (("association_unresolved.json", unresolved), ("association_ambiguous.json", ambiguous)):
|
| 142 |
+
(args.output_root / name).write_text(json.dumps(records, ensure_ascii=False, indent=2), encoding="utf-8")
|
| 143 |
+
summary = {
|
| 144 |
+
"created_at": time.time(),
|
| 145 |
+
"elapsed_seconds": round(time.time() - started, 3),
|
| 146 |
+
"inventory_records": len(inventory),
|
| 147 |
+
"recovered_records": len(recovered) - len(unresolved),
|
| 148 |
+
"unresolved_records": len(unresolved),
|
| 149 |
+
"ambiguous_records": len(ambiguous),
|
| 150 |
+
"raw_rows_scanned": raw_rows,
|
| 151 |
+
"raw_rows_missing_local_path": raw_missing_local,
|
| 152 |
+
"raw_rows_not_in_inventory": raw_not_inventory,
|
| 153 |
+
"source_counts": dict(source_counts),
|
| 154 |
+
"original_images_modified": False,
|
| 155 |
+
"remote_modified": False,
|
| 156 |
+
}
|
| 157 |
+
(args.output_root / "association_recovery_summary.json").write_text(json.dumps(summary, ensure_ascii=False, indent=2), encoding="utf-8")
|
| 158 |
+
print(json.dumps(summary, ensure_ascii=False), flush=True)
|
| 159 |
+
return 0
|
| 160 |
+
|
| 161 |
+
|
| 162 |
+
if __name__ == "__main__":
|
| 163 |
+
raise SystemExit(main())
|
reddit/_rescue_20260917/raw/scripts/resume_reddit_upload_after_rate_limit.ps1
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
param(
|
| 2 |
+
[int]$PollSeconds = 300
|
| 3 |
+
)
|
| 4 |
+
|
| 5 |
+
$ErrorActionPreference = 'Stop'
|
| 6 |
+
$python = 'C:\Users\zong zilu\AppData\Local\Programs\Python\Python313\python.exe'
|
| 7 |
+
$script = 'D:\GeoAgent\Geo-CoT dataset\外网图像地理定位数据收集\reddit_posts\upload_reddit_images_batched.py'
|
| 8 |
+
$watcher = 'D:\GeoAgent\Geo-CoT dataset\外网图像地理定位数据收集\reddit_posts\finalize_reddit_upload_manifest.ps1'
|
| 9 |
+
$log = 'C:\GeoAgent_hf_upload_cache\reddit\delayed_resume.log'
|
| 10 |
+
|
| 11 |
+
function Write-Log([string]$message) {
|
| 12 |
+
Add-Content -LiteralPath $log -Value "$(Get-Date -Format o) $message" -Encoding UTF8
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
Write-Log "poll_start seconds=$PollSeconds"
|
| 16 |
+
while ($true) {
|
| 17 |
+
$probeArgs = @(
|
| 18 |
+
$script, 'upload', '--batch-size', '10000', '--max-batch-bytes', '5368709120',
|
| 19 |
+
'--upload-threads', '8', '--request-timeout', '60', '--batch-retries', '1',
|
| 20 |
+
'--plan-only'
|
| 21 |
+
)
|
| 22 |
+
$probe = Start-Process -FilePath $python -ArgumentList $probeArgs -Wait -PassThru -WindowStyle Hidden
|
| 23 |
+
Write-Log "rate_limit_probe exit_code=$($probe.ExitCode)"
|
| 24 |
+
if ($probe.ExitCode -eq 0) { break }
|
| 25 |
+
Start-Sleep -Seconds $PollSeconds
|
| 26 |
+
}
|
| 27 |
+
Write-Log 'rate_limit_probe_ready starting_uploader'
|
| 28 |
+
|
| 29 |
+
$uploadArgs = @(
|
| 30 |
+
$script, 'upload', '--batch-size', '10000', '--max-batch-bytes', '5368709120',
|
| 31 |
+
'--upload-threads', '8', '--request-timeout', '180', '--batch-retries', '3',
|
| 32 |
+
'--rate-limit-backoff-seconds', '3700', '--rate-limit-poll-seconds', "$PollSeconds", '--heartbeat-seconds', '30'
|
| 33 |
+
)
|
| 34 |
+
$uploadInfo = [System.Diagnostics.ProcessStartInfo]::new()
|
| 35 |
+
$uploadInfo.FileName = $python
|
| 36 |
+
$uploadInfo.UseShellExecute = $true
|
| 37 |
+
$uploadInfo.CreateNoWindow = $true
|
| 38 |
+
$uploadInfo.WindowStyle = [System.Diagnostics.ProcessWindowStyle]::Hidden
|
| 39 |
+
foreach ($value in $uploadArgs) { $uploadInfo.ArgumentList.Add($value) }
|
| 40 |
+
$uploadProcess = [System.Diagnostics.Process]::Start($uploadInfo)
|
| 41 |
+
Write-Log "uploader_started pid=$($uploadProcess.Id)"
|
| 42 |
+
|
| 43 |
+
$watchArgs = @('-NoLogo', '-NoProfile', '-NonInteractive', '-File', $watcher, '-UploadProcessId', "$($uploadProcess.Id)")
|
| 44 |
+
$watchInfo = [System.Diagnostics.ProcessStartInfo]::new()
|
| 45 |
+
$watchInfo.FileName = (Get-Command pwsh.exe).Source
|
| 46 |
+
$watchInfo.UseShellExecute = $true
|
| 47 |
+
$watchInfo.CreateNoWindow = $true
|
| 48 |
+
$watchInfo.WindowStyle = [System.Diagnostics.ProcessWindowStyle]::Hidden
|
| 49 |
+
foreach ($value in $watchArgs) { $watchInfo.ArgumentList.Add($value) }
|
| 50 |
+
$watchProcess = [System.Diagnostics.Process]::Start($watchInfo)
|
| 51 |
+
Write-Log "watcher_started pid=$($watchProcess.Id)"
|
reddit/_rescue_20260917/raw/scripts/retry_circuit_skipped.py
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Retry only URLs skipped by the previous domain circuit breaker."""
|
| 2 |
+
|
| 3 |
+
import argparse
|
| 4 |
+
from collections import defaultdict
|
| 5 |
+
import json
|
| 6 |
+
import logging
|
| 7 |
+
import threading
|
| 8 |
+
import time
|
| 9 |
+
from concurrent.futures import ThreadPoolExecutor, as_completed
|
| 10 |
+
from pathlib import Path
|
| 11 |
+
from urllib.parse import urlparse
|
| 12 |
+
|
| 13 |
+
import retry_failed_images as downloader
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
def latest_records(path):
|
| 17 |
+
records = {}
|
| 18 |
+
for record in downloader.read_manifest(path):
|
| 19 |
+
records[record["url"]] = record
|
| 20 |
+
return records
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def main():
|
| 24 |
+
parser = argparse.ArgumentParser()
|
| 25 |
+
parser.add_argument("--community", default="PictureGame")
|
| 26 |
+
parser.add_argument("--workers", type=int, default=6)
|
| 27 |
+
parser.add_argument("--per-domain-workers", type=int, default=2)
|
| 28 |
+
parser.add_argument("--attempts", type=int, default=2)
|
| 29 |
+
parser.add_argument("--connect-timeout", type=int, default=10)
|
| 30 |
+
parser.add_argument("--max-time", type=int, default=30)
|
| 31 |
+
parser.add_argument("--min-free-gb", type=float, default=5.0)
|
| 32 |
+
parser.add_argument("--limit", type=int)
|
| 33 |
+
parser.add_argument("--restart", action="store_true")
|
| 34 |
+
parser.add_argument("--source", type=Path, default=Path(r"C:\GeoAgent_reddit_overflow\retry_state\PictureGame\extended_retry_state.jsonl"))
|
| 35 |
+
parser.add_argument("--overflow-root", type=Path, default=downloader.DEFAULT_OVERFLOW_ROOT)
|
| 36 |
+
parser.add_argument("--state-root", type=Path, default=downloader.DEFAULT_STATE_ROOT)
|
| 37 |
+
args = parser.parse_args()
|
| 38 |
+
|
| 39 |
+
if min(args.workers, args.per_domain_workers, args.attempts, args.connect_timeout, args.max_time) <= 0:
|
| 40 |
+
raise ValueError("workers, attempts and timeouts must be positive")
|
| 41 |
+
|
| 42 |
+
community_dir = downloader.OUT_ROOT / args.community
|
| 43 |
+
primary_dir = community_dir / "images"
|
| 44 |
+
overflow_dir = args.overflow_root / args.community / "images"
|
| 45 |
+
state_dir = args.state_root / args.community
|
| 46 |
+
state_dir.mkdir(parents=True, exist_ok=True)
|
| 47 |
+
checkpoint_path = state_dir / "circuit_retry_state.jsonl"
|
| 48 |
+
log_path = state_dir / "circuit_retry.log"
|
| 49 |
+
output_path = state_dir / "image_manifest_circuit_retry.jsonl"
|
| 50 |
+
logging.basicConfig(filename=log_path, level=logging.INFO, format="%(asctime)s %(levelname)s %(message)s", force=True)
|
| 51 |
+
|
| 52 |
+
candidates = [r for r in latest_records(args.source).values() if r.get("error") == "domain_circuit_open"]
|
| 53 |
+
candidates.sort(key=lambda r: (urlparse(r["url"]).netloc.lower(), r["url"]))
|
| 54 |
+
if args.limit is not None:
|
| 55 |
+
candidates = candidates[:args.limit]
|
| 56 |
+
|
| 57 |
+
checkpoint = {}
|
| 58 |
+
if checkpoint_path.exists() and not args.restart:
|
| 59 |
+
checkpoint = latest_records(checkpoint_path)
|
| 60 |
+
pending = [r for r in candidates if r["url"] not in checkpoint]
|
| 61 |
+
existing = downloader.build_existing_index([primary_dir, overflow_dir])
|
| 62 |
+
minimum = int(args.min_free_gb * 1024 ** 3)
|
| 63 |
+
|
| 64 |
+
downloader.ATTEMPTS = args.attempts
|
| 65 |
+
downloader.CONNECT_TIMEOUT = args.connect_timeout
|
| 66 |
+
downloader.MAX_TIME = args.max_time
|
| 67 |
+
downloader.domain_is_open = lambda _url: False
|
| 68 |
+
downloader.update_domain_health = lambda _url, _succeeded: None
|
| 69 |
+
|
| 70 |
+
index_lock = threading.Lock()
|
| 71 |
+
domain_locks = defaultdict(lambda: threading.BoundedSemaphore(args.per_domain_workers))
|
| 72 |
+
|
| 73 |
+
def retry(record):
|
| 74 |
+
with index_lock:
|
| 75 |
+
known = existing.get(downloader.image_stem(record["url"]))
|
| 76 |
+
if known:
|
| 77 |
+
return {**record, "status": "ok", "local_path": str(known), "bytes": known.stat().st_size,
|
| 78 |
+
"error": None, "retry_attempts": 0, "reused": True}
|
| 79 |
+
domain = urlparse(record["url"]).netloc.lower()
|
| 80 |
+
with domain_locks[domain]:
|
| 81 |
+
return downloader.retry_one(record, primary_dir, overflow_dir, minimum, existing, True)
|
| 82 |
+
|
| 83 |
+
logging.info("prepared candidates=%s checkpoint=%s pending=%s", len(candidates), len(checkpoint), len(pending))
|
| 84 |
+
print(json.dumps({"candidates": len(candidates), "checkpoint": len(checkpoint), "pending": len(pending)}, ensure_ascii=False), flush=True)
|
| 85 |
+
mode = "w" if args.restart else "a"
|
| 86 |
+
started = time.time()
|
| 87 |
+
ok = sum(r.get("status") == "ok" for r in checkpoint.values())
|
| 88 |
+
failed = sum(r.get("status") == "failed" for r in checkpoint.values())
|
| 89 |
+
with checkpoint_path.open(mode, encoding="utf-8") as handle, ThreadPoolExecutor(max_workers=args.workers) as pool:
|
| 90 |
+
futures = [pool.submit(retry, record) for record in pending]
|
| 91 |
+
for index, future in enumerate(as_completed(futures), 1):
|
| 92 |
+
result = future.result()
|
| 93 |
+
if result.get("status") == "internal_error":
|
| 94 |
+
raise RuntimeError(f"internal downloader error: {result.get('error')}")
|
| 95 |
+
checkpoint[result["url"]] = result
|
| 96 |
+
handle.write(json.dumps(result, ensure_ascii=False, separators=(",", ":")) + "\n")
|
| 97 |
+
handle.flush()
|
| 98 |
+
ok += result.get("status") == "ok"
|
| 99 |
+
failed += result.get("status") == "failed"
|
| 100 |
+
if index % 25 == 0 or index == len(pending):
|
| 101 |
+
completed = len(checkpoint)
|
| 102 |
+
speed = index / max(time.time() - started, 0.001)
|
| 103 |
+
logging.info("progress=%s/%s ok=%s failed=%s speed=%.2f records/s", completed, len(candidates), ok, failed, speed)
|
| 104 |
+
print(json.dumps({"progress": completed, "total": len(candidates), "ok": ok, "failed": failed, "speed": round(speed, 3)}), flush=True)
|
| 105 |
+
|
| 106 |
+
downloader.write_jsonl(output_path, checkpoint.values())
|
| 107 |
+
final = {"status": "complete", "candidates": len(candidates), "ok": ok, "failed": failed, "output": str(output_path)}
|
| 108 |
+
logging.info("complete %s", json.dumps(final, ensure_ascii=False))
|
| 109 |
+
print(json.dumps(final, ensure_ascii=False), flush=True)
|
| 110 |
+
|
| 111 |
+
|
| 112 |
+
if __name__ == "__main__":
|
| 113 |
+
main()
|
reddit/_rescue_20260917/raw/scripts/retry_failed_after_completion.py
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Run an extended retry pass after the primary downloader exits.
|
| 2 |
+
|
| 3 |
+
This script waits for the primary PID, reads the latest checkpoint on C:, and
|
| 4 |
+
retries only the latest failed record for each URL. Existing images are reused.
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
import argparse
|
| 8 |
+
import json
|
| 9 |
+
import logging
|
| 10 |
+
import time
|
| 11 |
+
from concurrent.futures import ThreadPoolExecutor, as_completed
|
| 12 |
+
from pathlib import Path
|
| 13 |
+
|
| 14 |
+
import retry_failed_images as downloader
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def wait_for_pid(pid, poll_seconds):
|
| 18 |
+
while True:
|
| 19 |
+
try:
|
| 20 |
+
import psutil
|
| 21 |
+
if not psutil.pid_exists(pid):
|
| 22 |
+
return
|
| 23 |
+
except ImportError:
|
| 24 |
+
try:
|
| 25 |
+
import subprocess
|
| 26 |
+
result = subprocess.run(["tasklist", "/FI", f"PID eq {pid}"], capture_output=True, text=True)
|
| 27 |
+
if str(pid) not in result.stdout:
|
| 28 |
+
return
|
| 29 |
+
except OSError:
|
| 30 |
+
return
|
| 31 |
+
time.sleep(poll_seconds)
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
def latest_records(path):
|
| 35 |
+
latest = {}
|
| 36 |
+
for record in downloader.read_manifest(path):
|
| 37 |
+
latest[record["url"]] = record
|
| 38 |
+
return latest
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
def retry_community(name, args):
|
| 42 |
+
community_dir = downloader.OUT_ROOT / name
|
| 43 |
+
primary_dir = community_dir / "images"
|
| 44 |
+
overflow_dir = args.overflow_root / name / "images"
|
| 45 |
+
state_dir = args.state_root / name
|
| 46 |
+
checkpoint = state_dir / "retry_state.jsonl"
|
| 47 |
+
log_path = state_dir / "extended_retry.log"
|
| 48 |
+
state_out = state_dir / "extended_retry_state.jsonl"
|
| 49 |
+
manifest_out = state_dir / "image_manifest_extended_retry.jsonl"
|
| 50 |
+
logging.basicConfig(filename=log_path, level=logging.INFO,
|
| 51 |
+
format="%(asctime)s %(levelname)s %(message)s", force=True)
|
| 52 |
+
|
| 53 |
+
latest = latest_records(checkpoint)
|
| 54 |
+
candidates = [r for r in latest.values() if r.get("status") == "failed"]
|
| 55 |
+
if not args.retry_all:
|
| 56 |
+
candidates = [r for r in candidates if downloader.should_retry(r, False)]
|
| 57 |
+
if args.limit is not None:
|
| 58 |
+
candidates = candidates[:args.limit]
|
| 59 |
+
|
| 60 |
+
existing = downloader.build_existing_index([primary_dir, overflow_dir])
|
| 61 |
+
minimum = int(args.min_free_gb * 1024 ** 3)
|
| 62 |
+
logging.info("prepared community=%s candidates=%s existing_images=%s", name, len(candidates), len(existing))
|
| 63 |
+
print(json.dumps({"community": name, "candidates": len(candidates), "existing_images": len(existing)}, ensure_ascii=False), flush=True)
|
| 64 |
+
|
| 65 |
+
ok = failed = internal = 0
|
| 66 |
+
results = {}
|
| 67 |
+
with state_out.open("w", encoding="utf-8") as handle:
|
| 68 |
+
with ThreadPoolExecutor(max_workers=args.workers) as pool:
|
| 69 |
+
futures = [pool.submit(extended_retry_one, r, primary_dir, overflow_dir, minimum, existing, args) for r in candidates]
|
| 70 |
+
for index, future in enumerate(as_completed(futures), 1):
|
| 71 |
+
result = future.result()
|
| 72 |
+
if result.get("status") == "internal_error":
|
| 73 |
+
internal += 1
|
| 74 |
+
raise RuntimeError(f"internal error: {result.get('error')}")
|
| 75 |
+
results[result["url"]] = result
|
| 76 |
+
handle.write(json.dumps(result, ensure_ascii=False, separators=(",", ":")) + "\n")
|
| 77 |
+
handle.flush()
|
| 78 |
+
if result["status"] == "ok":
|
| 79 |
+
ok += 1
|
| 80 |
+
else:
|
| 81 |
+
failed += 1
|
| 82 |
+
if index % args.batch_log == 0 or index == len(candidates):
|
| 83 |
+
logging.info("progress=%s/%s ok=%s failed=%s", index, len(candidates), ok, failed)
|
| 84 |
+
print(json.dumps({"community": name, "progress": index, "total": len(candidates), "ok": ok, "failed": failed}, ensure_ascii=False), flush=True)
|
| 85 |
+
|
| 86 |
+
original = list(downloader.read_manifest(community_dir / "image_manifest.jsonl"))
|
| 87 |
+
merged = [results.get(r["url"], r) if r.get("status") == "failed" else r for r in original]
|
| 88 |
+
downloader.write_jsonl(manifest_out, merged)
|
| 89 |
+
final = {"community": name, "status": "complete", "candidates": len(candidates), "ok": ok, "failed": failed, "internal": internal, "output": str(manifest_out)}
|
| 90 |
+
logging.info("complete %s", json.dumps(final, ensure_ascii=False))
|
| 91 |
+
print(json.dumps(final, ensure_ascii=False), flush=True)
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
def extended_retry_one(record, primary_dir, overflow_dir, minimum, existing, args):
|
| 95 |
+
downloader.ATTEMPTS = args.attempts
|
| 96 |
+
downloader.CONNECT_TIMEOUT = args.connect_timeout
|
| 97 |
+
downloader.MAX_TIME = args.max_time
|
| 98 |
+
return downloader.retry_one(record, primary_dir, overflow_dir, minimum, existing, True)
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
def main():
|
| 102 |
+
parser = argparse.ArgumentParser()
|
| 103 |
+
parser.add_argument("--wait-pid", type=int, required=True)
|
| 104 |
+
parser.add_argument("--communities", nargs="+", choices=["whereisthis", "GeoPuzzle", "PictureGame"], default=["PictureGame"])
|
| 105 |
+
parser.add_argument("--workers", type=int, default=4)
|
| 106 |
+
parser.add_argument("--attempts", type=int, default=5)
|
| 107 |
+
parser.add_argument("--connect-timeout", type=int, default=15)
|
| 108 |
+
parser.add_argument("--max-time", type=int, default=60)
|
| 109 |
+
parser.add_argument("--min-free-gb", type=float, default=5.0)
|
| 110 |
+
parser.add_argument("--batch-log", type=int, default=16)
|
| 111 |
+
parser.add_argument("--limit", type=int)
|
| 112 |
+
parser.add_argument("--retry-all", action="store_true")
|
| 113 |
+
parser.add_argument("--overflow-root", type=Path, default=downloader.DEFAULT_OVERFLOW_ROOT)
|
| 114 |
+
parser.add_argument("--state-root", type=Path, default=downloader.DEFAULT_STATE_ROOT)
|
| 115 |
+
args = parser.parse_args()
|
| 116 |
+
print(json.dumps({"waiting_for_pid": args.wait_pid}, ensure_ascii=False), flush=True)
|
| 117 |
+
wait_for_pid(args.wait_pid, 10)
|
| 118 |
+
for name in args.communities:
|
| 119 |
+
retry_community(name, args)
|
| 120 |
+
|
| 121 |
+
|
| 122 |
+
if __name__ == "__main__":
|
| 123 |
+
main()
|
reddit/_rescue_20260917/raw/scripts/retry_failed_images.py
ADDED
|
@@ -0,0 +1,328 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Retry failed image URLs from the three-community collection.
|
| 2 |
+
|
| 3 |
+
The original manifest is never modified. Results are checkpointed per URL and
|
| 4 |
+
the merged manifest is written only after a community finishes.
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
import argparse
|
| 8 |
+
import json
|
| 9 |
+
import logging
|
| 10 |
+
import os
|
| 11 |
+
import re
|
| 12 |
+
import shutil
|
| 13 |
+
import subprocess
|
| 14 |
+
import threading
|
| 15 |
+
import time
|
| 16 |
+
from concurrent.futures import ThreadPoolExecutor, as_completed
|
| 17 |
+
from pathlib import Path
|
| 18 |
+
from urllib.parse import urlparse
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
ROOT = Path(__file__).resolve().parent
|
| 22 |
+
OUT_ROOT = ROOT / "solved_communities"
|
| 23 |
+
DEFAULT_WORKERS = 12
|
| 24 |
+
BATCH_SIZE = 32
|
| 25 |
+
ATTEMPTS = 2
|
| 26 |
+
CONNECT_TIMEOUT = 5
|
| 27 |
+
MAX_TIME = 15
|
| 28 |
+
DEFAULT_MIN_FREE_GB = 5.0
|
| 29 |
+
DEFAULT_OVERFLOW_ROOT = Path(r"C:\GeoAgent_reddit_overflow\solved_communities")
|
| 30 |
+
DEFAULT_STATE_ROOT = Path(r"C:\GeoAgent_reddit_overflow\retry_state")
|
| 31 |
+
DOMAIN_FAILURE_LIMIT = 8
|
| 32 |
+
URL_RE = re.compile(r"https?://[^\s<>\[\]()\"']+", re.I)
|
| 33 |
+
_storage_notice_lock = threading.Lock()
|
| 34 |
+
_storage_notice_emitted = set()
|
| 35 |
+
_domain_lock = threading.Lock()
|
| 36 |
+
_domain_failures = {}
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
def image_stem(url):
|
| 40 |
+
import hashlib
|
| 41 |
+
return hashlib.sha256(url.encode("utf-8")).hexdigest()[:24]
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
def detected_extension(path):
|
| 45 |
+
try:
|
| 46 |
+
with path.open("rb") as handle:
|
| 47 |
+
head = handle.read(512)
|
| 48 |
+
except OSError:
|
| 49 |
+
return None
|
| 50 |
+
if head.startswith(b"\xff\xd8\xff"):
|
| 51 |
+
return ".jpg"
|
| 52 |
+
if head.startswith(b"\x89PNG\r\n\x1a\n"):
|
| 53 |
+
return ".png"
|
| 54 |
+
if head[:6] in (b"GIF87a", b"GIF89a"):
|
| 55 |
+
return ".gif"
|
| 56 |
+
if head.startswith(b"RIFF") and head[8:12] == b"WEBP":
|
| 57 |
+
return ".webp"
|
| 58 |
+
if head.startswith(b"BM"):
|
| 59 |
+
return ".bmp"
|
| 60 |
+
if head.startswith((b"II*\x00", b"MM\x00*")):
|
| 61 |
+
return ".tiff"
|
| 62 |
+
if len(head) >= 12 and head[4:12] in (b"ftypavif", b"ftypavis"):
|
| 63 |
+
return ".avif"
|
| 64 |
+
lowered = head.lstrip().lower()
|
| 65 |
+
if lowered.startswith(b"<svg") or (lowered.startswith(b"<?xml") and b"<svg" in lowered):
|
| 66 |
+
return ".svg"
|
| 67 |
+
return None
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
def error_kind(error):
|
| 71 |
+
text = error or "unknown"
|
| 72 |
+
if "404" in text:
|
| 73 |
+
return "http_404"
|
| 74 |
+
if "403" in text:
|
| 75 |
+
return "http_403"
|
| 76 |
+
if "429" in text:
|
| 77 |
+
return "http_429"
|
| 78 |
+
if re.search(r"\b4\d\d\b", text):
|
| 79 |
+
return "http_4xx"
|
| 80 |
+
if re.search(r"\b5\d\d\b", text):
|
| 81 |
+
return "http_5xx"
|
| 82 |
+
if "timed out" in text.lower() or "timeout" in text.lower():
|
| 83 |
+
return "timeout"
|
| 84 |
+
if "Empty reply" in text:
|
| 85 |
+
return "empty_reply"
|
| 86 |
+
if "SSL" in text or "TLS" in text or "handshake" in text:
|
| 87 |
+
return "tls_ssl"
|
| 88 |
+
if "Malformed" in text:
|
| 89 |
+
return "malformed_url"
|
| 90 |
+
return "other"
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
def should_retry(record, retry_all):
|
| 94 |
+
if retry_all:
|
| 95 |
+
return True
|
| 96 |
+
return error_kind(record.get("error")) not in {"http_404", "http_403", "http_4xx", "malformed_url"}
|
| 97 |
+
|
| 98 |
+
|
| 99 |
+
def request_urls(url):
|
| 100 |
+
"""Prefer HTTPS for legacy HTTP links, then retain the original URL as fallback."""
|
| 101 |
+
if url.lower().startswith("http://"):
|
| 102 |
+
https_url = "https://" + url[7:]
|
| 103 |
+
return [https_url, url]
|
| 104 |
+
return [url]
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
def attempts_for_error(record):
|
| 108 |
+
kind = error_kind(record.get("error"))
|
| 109 |
+
if kind in {"http_404", "http_403", "http_4xx", "malformed_url"}:
|
| 110 |
+
return 1
|
| 111 |
+
return ATTEMPTS
|
| 112 |
+
|
| 113 |
+
|
| 114 |
+
def build_existing_index(image_dirs):
|
| 115 |
+
index = {}
|
| 116 |
+
for image_dir in image_dirs:
|
| 117 |
+
if not image_dir.exists():
|
| 118 |
+
continue
|
| 119 |
+
for path in image_dir.iterdir():
|
| 120 |
+
if path.is_file() and not path.name.endswith(".part") and path.stat().st_size > 0:
|
| 121 |
+
index.setdefault(path.stem, path)
|
| 122 |
+
return index
|
| 123 |
+
|
| 124 |
+
|
| 125 |
+
def domain_is_open(url):
|
| 126 |
+
domain = urlparse(url).netloc.lower()
|
| 127 |
+
with _domain_lock:
|
| 128 |
+
return _domain_failures.get(domain, 0) >= DOMAIN_FAILURE_LIMIT
|
| 129 |
+
|
| 130 |
+
|
| 131 |
+
def update_domain_health(url, succeeded):
|
| 132 |
+
domain = urlparse(url).netloc.lower()
|
| 133 |
+
with _domain_lock:
|
| 134 |
+
_domain_failures[domain] = 0 if succeeded else _domain_failures.get(domain, 0) + 1
|
| 135 |
+
|
| 136 |
+
|
| 137 |
+
def select_image_dir(primary_dir, overflow_dir, min_free_bytes, force_overflow=False):
|
| 138 |
+
if force_overflow:
|
| 139 |
+
overflow_dir.mkdir(parents=True, exist_ok=True)
|
| 140 |
+
overflow_free = shutil.disk_usage(overflow_dir.anchor).free
|
| 141 |
+
if overflow_free < min_free_bytes:
|
| 142 |
+
raise OSError(
|
| 143 |
+
f"overflow volume is below the safety threshold: "
|
| 144 |
+
f"overflow_free={overflow_free}, threshold={min_free_bytes}"
|
| 145 |
+
)
|
| 146 |
+
return overflow_dir
|
| 147 |
+
primary_free = shutil.disk_usage(primary_dir.anchor).free
|
| 148 |
+
if primary_free >= min_free_bytes:
|
| 149 |
+
return primary_dir
|
| 150 |
+
overflow_dir.mkdir(parents=True, exist_ok=True)
|
| 151 |
+
overflow_free = shutil.disk_usage(overflow_dir.anchor).free
|
| 152 |
+
if overflow_free < min_free_bytes:
|
| 153 |
+
raise OSError(
|
| 154 |
+
f"both storage volumes are below the safety threshold: "
|
| 155 |
+
f"primary_free={primary_free}, overflow_free={overflow_free}, "
|
| 156 |
+
f"threshold={min_free_bytes}"
|
| 157 |
+
)
|
| 158 |
+
notice_key = str(overflow_dir)
|
| 159 |
+
with _storage_notice_lock:
|
| 160 |
+
if notice_key not in _storage_notice_emitted:
|
| 161 |
+
logging.warning(
|
| 162 |
+
"storage_switch primary=%s primary_free_gb=%.2f overflow=%s overflow_free_gb=%.2f threshold_gb=%.2f",
|
| 163 |
+
primary_dir,
|
| 164 |
+
primary_free / (1024 ** 3),
|
| 165 |
+
overflow_dir,
|
| 166 |
+
overflow_free / (1024 ** 3),
|
| 167 |
+
min_free_bytes / (1024 ** 3),
|
| 168 |
+
)
|
| 169 |
+
_storage_notice_emitted.add(notice_key)
|
| 170 |
+
return overflow_dir
|
| 171 |
+
|
| 172 |
+
|
| 173 |
+
def retry_one(record, primary_image_dir, overflow_image_dir, min_free_bytes, existing_index, force_overflow):
|
| 174 |
+
url = record["url"]
|
| 175 |
+
reused = existing_index.get(image_stem(url))
|
| 176 |
+
if reused:
|
| 177 |
+
return {**record, "status": "ok", "local_path": str(reused), "bytes": reused.stat().st_size, "error": None, "retry_attempts": 0, "reused": True}
|
| 178 |
+
if domain_is_open(url):
|
| 179 |
+
return {**record, "status": "failed", "local_path": None, "bytes": 0, "error": "domain_circuit_open", "retry_attempts": 0, "reused": False}
|
| 180 |
+
|
| 181 |
+
image_dir = select_image_dir(primary_image_dir, overflow_image_dir, min_free_bytes, force_overflow)
|
| 182 |
+
partial = image_dir / (image_stem(url) + ".retry.part")
|
| 183 |
+
last_error = ""
|
| 184 |
+
max_attempts = attempts_for_error(record)
|
| 185 |
+
for attempt in range(1, max_attempts + 1):
|
| 186 |
+
for request_url in request_urls(url):
|
| 187 |
+
try:
|
| 188 |
+
partial.unlink(missing_ok=True)
|
| 189 |
+
command = [
|
| 190 |
+
"curl.exe", "--location", "--fail", "--silent", "--show-error",
|
| 191 |
+
"--connect-timeout", str(CONNECT_TIMEOUT), "--max-time", str(MAX_TIME),
|
| 192 |
+
"--user-agent", "GeoAgent research image retry/1.0",
|
| 193 |
+
"--referer", "https://www.reddit.com/",
|
| 194 |
+
"--header", "Accept: image/avif,image/webp,image/apng,image/*,*/*;q=0.8",
|
| 195 |
+
"--output", str(partial), request_url,
|
| 196 |
+
]
|
| 197 |
+
result = subprocess.run(command, capture_output=True, text=True, timeout=MAX_TIME + 10)
|
| 198 |
+
actual = detected_extension(partial) if partial.exists() else None
|
| 199 |
+
if result.returncode == 0 and actual:
|
| 200 |
+
final_path = image_dir / (image_stem(url) + actual)
|
| 201 |
+
partial.replace(final_path)
|
| 202 |
+
existing_index[image_stem(url)] = final_path
|
| 203 |
+
update_domain_health(url, True)
|
| 204 |
+
return {**record, "status": "ok", "local_path": str(final_path), "bytes": final_path.stat().st_size, "error": None, "retry_attempts": attempt, "reused": False}
|
| 205 |
+
last_error = (result.stderr or "not_a_supported_image").strip()[-500:]
|
| 206 |
+
if error_kind(last_error) in {"http_404", "http_403", "http_4xx", "http_429", "http_5xx", "malformed_url"}:
|
| 207 |
+
break
|
| 208 |
+
except subprocess.TimeoutExpired as exc:
|
| 209 |
+
last_error = str(exc)[-500:]
|
| 210 |
+
except (OSError, ValueError, TypeError) as exc:
|
| 211 |
+
return {**record, "status": "internal_error", "local_path": None, "bytes": 0, "error": str(exc)[-500:], "retry_attempts": attempt, "reused": False}
|
| 212 |
+
if attempt < max_attempts:
|
| 213 |
+
kind = error_kind(last_error)
|
| 214 |
+
time.sleep(5 if kind == "http_429" else (2 ** (attempt - 1)))
|
| 215 |
+
partial.unlink(missing_ok=True)
|
| 216 |
+
update_domain_health(url, False)
|
| 217 |
+
return {**record, "status": "failed", "local_path": None, "bytes": 0, "error": last_error or "retry_failed", "retry_attempts": max_attempts, "reused": False}
|
| 218 |
+
|
| 219 |
+
|
| 220 |
+
def read_manifest(path):
|
| 221 |
+
with path.open("r", encoding="utf-8") as handle:
|
| 222 |
+
for line in handle:
|
| 223 |
+
if line.strip():
|
| 224 |
+
yield json.loads(line)
|
| 225 |
+
|
| 226 |
+
|
| 227 |
+
def write_jsonl(path, records):
|
| 228 |
+
temporary = path.with_suffix(path.suffix + ".part")
|
| 229 |
+
with temporary.open("w", encoding="utf-8") as handle:
|
| 230 |
+
for record in records:
|
| 231 |
+
handle.write(json.dumps(record, ensure_ascii=False, separators=(",", ":")) + "\n")
|
| 232 |
+
temporary.replace(path)
|
| 233 |
+
|
| 234 |
+
|
| 235 |
+
def process_community(name, workers, retry_all, restart, overflow_root, state_root, min_free_gb, force_overflow, limit=None):
|
| 236 |
+
community_dir = OUT_ROOT / name
|
| 237 |
+
manifest_path = community_dir / "image_manifest.jsonl"
|
| 238 |
+
image_dir = community_dir / "images"
|
| 239 |
+
overflow_image_dir = overflow_root / name / "images"
|
| 240 |
+
min_free_bytes = int(min_free_gb * 1024 ** 3)
|
| 241 |
+
state_dir = state_root / name
|
| 242 |
+
state_dir.mkdir(parents=True, exist_ok=True)
|
| 243 |
+
checkpoint_path = state_dir / "retry_state.jsonl"
|
| 244 |
+
output_path = state_dir / "image_manifest_retry.jsonl"
|
| 245 |
+
log_path = state_dir / "retry_failed_images.log"
|
| 246 |
+
logging.basicConfig(filename=log_path, level=logging.INFO, format="%(asctime)s %(levelname)s %(message)s", force=True)
|
| 247 |
+
|
| 248 |
+
records = list(read_manifest(manifest_path))
|
| 249 |
+
existing_index = build_existing_index([image_dir, overflow_image_dir])
|
| 250 |
+
record_by_url = {record["url"]: record for record in records}
|
| 251 |
+
candidates = [record for record in records if record.get("status") == "failed" and should_retry(record, retry_all)]
|
| 252 |
+
if limit is not None:
|
| 253 |
+
candidates = candidates[:limit]
|
| 254 |
+
checkpoint = {}
|
| 255 |
+
if checkpoint_path.exists() and not restart:
|
| 256 |
+
checkpoint = {record["url"]: record for record in read_manifest(checkpoint_path)}
|
| 257 |
+
pending = [record for record in candidates if record["url"] not in checkpoint]
|
| 258 |
+
logging.info("prepared community=%s candidates=%s checkpoint=%s pending=%s existing_images=%s retry_all=%s", name, len(candidates), len(checkpoint), len(pending), len(existing_index), retry_all)
|
| 259 |
+
print(json.dumps({"community": name, "candidates": len(candidates), "checkpoint": len(checkpoint), "pending": len(pending)}, ensure_ascii=False), flush=True)
|
| 260 |
+
|
| 261 |
+
checkpoint_path.parent.mkdir(parents=True, exist_ok=True)
|
| 262 |
+
checkpoint_handle = checkpoint_path.open("w" if restart else "a", encoding="utf-8")
|
| 263 |
+
ok = sum(record.get("status") == "ok" for record in checkpoint.values())
|
| 264 |
+
failed = sum(record.get("status") == "failed" for record in checkpoint.values())
|
| 265 |
+
started = time.time()
|
| 266 |
+
internal_errors = 0
|
| 267 |
+
try:
|
| 268 |
+
for offset in range(0, len(pending), BATCH_SIZE):
|
| 269 |
+
batch = pending[offset:offset + BATCH_SIZE]
|
| 270 |
+
with ThreadPoolExecutor(max_workers=max(1, workers)) as executor:
|
| 271 |
+
futures = [
|
| 272 |
+
executor.submit(retry_one, record, image_dir, overflow_image_dir, min_free_bytes, existing_index, force_overflow)
|
| 273 |
+
for record in batch
|
| 274 |
+
]
|
| 275 |
+
for future in as_completed(futures):
|
| 276 |
+
result = future.result()
|
| 277 |
+
if result.get("status") == "internal_error":
|
| 278 |
+
internal_errors += 1
|
| 279 |
+
raise RuntimeError(f"internal downloader error for {result['url']}: {result.get('error')}")
|
| 280 |
+
checkpoint[result["url"]] = result
|
| 281 |
+
checkpoint_handle.write(json.dumps(result, ensure_ascii=False, separators=(",", ":")) + "\n")
|
| 282 |
+
checkpoint_handle.flush()
|
| 283 |
+
if result["status"] == "ok":
|
| 284 |
+
ok += 1
|
| 285 |
+
else:
|
| 286 |
+
failed += 1
|
| 287 |
+
completed = len(checkpoint)
|
| 288 |
+
speed = completed / max(time.time() - started, 0.001)
|
| 289 |
+
logging.info("progress=%s/%s ok=%s failed=%s speed=%.2f records/s", completed, len(candidates), ok, failed, speed)
|
| 290 |
+
print(json.dumps({"community": name, "progress": completed, "total": len(candidates), "ok": ok, "failed": failed, "speed": round(speed, 3)}, ensure_ascii=False), flush=True)
|
| 291 |
+
finally:
|
| 292 |
+
checkpoint_handle.close()
|
| 293 |
+
|
| 294 |
+
merged = []
|
| 295 |
+
for record in records:
|
| 296 |
+
merged.append(checkpoint.get(record["url"], record))
|
| 297 |
+
write_jsonl(output_path, merged)
|
| 298 |
+
final = {"community": name, "status": "complete", "candidates": len(candidates), "retried": len(checkpoint), "retry_ok": ok, "retry_failed": failed, "output": str(output_path)}
|
| 299 |
+
logging.info("complete %s", json.dumps(final, ensure_ascii=False))
|
| 300 |
+
print(json.dumps(final, ensure_ascii=False), flush=True)
|
| 301 |
+
return final
|
| 302 |
+
|
| 303 |
+
|
| 304 |
+
def main():
|
| 305 |
+
parser = argparse.ArgumentParser(description="Retry failed image downloads without modifying the original manifests")
|
| 306 |
+
parser.add_argument("--communities", nargs="+", choices=["whereisthis", "GeoPuzzle", "PictureGame"], default=["whereisthis", "GeoPuzzle", "PictureGame"])
|
| 307 |
+
parser.add_argument("--workers", type=int, default=DEFAULT_WORKERS)
|
| 308 |
+
parser.add_argument("--retry-all", action="store_true", help="also retry HTTP 404, 403 and malformed URLs")
|
| 309 |
+
parser.add_argument("--restart", action="store_true", help="ignore retry_state.jsonl and retry selected failures again")
|
| 310 |
+
parser.add_argument("--limit", type=int, help="process only the first N candidates per community for validation")
|
| 311 |
+
parser.add_argument("--overflow-root", type=Path, default=DEFAULT_OVERFLOW_ROOT, help="secondary image root used when the primary volume is low")
|
| 312 |
+
parser.add_argument("--state-root", type=Path, default=DEFAULT_STATE_ROOT, help="root for logs, checkpoints and merged retry manifests")
|
| 313 |
+
parser.add_argument("--force-overflow", action="store_true", help="always write new images to the overflow root")
|
| 314 |
+
parser.add_argument("--min-free-gb", type=float, default=DEFAULT_MIN_FREE_GB, help="switch volumes when free space is below this threshold")
|
| 315 |
+
args = parser.parse_args()
|
| 316 |
+
if not isinstance(MAX_TIME, int) or not isinstance(CONNECT_TIMEOUT, int):
|
| 317 |
+
raise TypeError("timeout constants must be integers")
|
| 318 |
+
if args.min_free_gb <= 0:
|
| 319 |
+
raise ValueError("--min-free-gb must be greater than zero")
|
| 320 |
+
summaries = [
|
| 321 |
+
process_community(name, args.workers, args.retry_all, args.restart, args.overflow_root, args.state_root, args.min_free_gb, args.force_overflow, args.limit)
|
| 322 |
+
for name in args.communities
|
| 323 |
+
]
|
| 324 |
+
print(json.dumps({"status": "complete", "communities": summaries}, ensure_ascii=False), flush=True)
|
| 325 |
+
|
| 326 |
+
|
| 327 |
+
if __name__ == "__main__":
|
| 328 |
+
main()
|
reddit/_rescue_20260917/raw/scripts/retry_recoverable_284.py
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Retry the recoverable subset left by retry_circuit_skipped.py."""
|
| 2 |
+
|
| 3 |
+
import argparse
|
| 4 |
+
import json
|
| 5 |
+
import logging
|
| 6 |
+
import re
|
| 7 |
+
import threading
|
| 8 |
+
import time
|
| 9 |
+
from collections import defaultdict
|
| 10 |
+
from concurrent.futures import ThreadPoolExecutor, as_completed
|
| 11 |
+
from pathlib import Path
|
| 12 |
+
from urllib.parse import urlparse
|
| 13 |
+
|
| 14 |
+
import retry_failed_images as downloader
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def latest_records(path):
|
| 18 |
+
records = {}
|
| 19 |
+
for record in downloader.read_manifest(path):
|
| 20 |
+
records[record["url"]] = record
|
| 21 |
+
return records
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
def recoverable(error):
|
| 25 |
+
text = error or ""
|
| 26 |
+
return bool(
|
| 27 |
+
"429" in text
|
| 28 |
+
or "Empty reply" in text
|
| 29 |
+
or re.search(r"\b5\d\d\b", text)
|
| 30 |
+
or "timed out" in text.lower()
|
| 31 |
+
or "timeout" in text.lower()
|
| 32 |
+
or any(token in text for token in ("SSL", "TLS", "schannel", "handshake"))
|
| 33 |
+
)
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
def main():
|
| 37 |
+
parser = argparse.ArgumentParser()
|
| 38 |
+
parser.add_argument("--source", type=Path, default=Path(r"C:\GeoAgent_reddit_overflow\retry_state\PictureGame\circuit_retry_state.jsonl"))
|
| 39 |
+
parser.add_argument("--workers", type=int, default=4)
|
| 40 |
+
parser.add_argument("--attempts", type=int, default=3)
|
| 41 |
+
parser.add_argument("--connect-timeout", type=int, default=20)
|
| 42 |
+
parser.add_argument("--max-time", type=int, default=60)
|
| 43 |
+
parser.add_argument("--domain-delay", type=float, default=3.0)
|
| 44 |
+
parser.add_argument("--min-free-gb", type=float, default=5.0)
|
| 45 |
+
parser.add_argument("--limit", type=int)
|
| 46 |
+
parser.add_argument("--restart", action="store_true")
|
| 47 |
+
args = parser.parse_args()
|
| 48 |
+
|
| 49 |
+
community = "PictureGame"
|
| 50 |
+
primary_dir = downloader.OUT_ROOT / community / "images"
|
| 51 |
+
overflow_dir = downloader.DEFAULT_OVERFLOW_ROOT / community / "images"
|
| 52 |
+
state_dir = downloader.DEFAULT_STATE_ROOT / community
|
| 53 |
+
state_dir.mkdir(parents=True, exist_ok=True)
|
| 54 |
+
state_path = state_dir / "recoverable_284_state.jsonl"
|
| 55 |
+
log_path = state_dir / "recoverable_284.log"
|
| 56 |
+
output_path = state_dir / "image_manifest_recoverable_284.jsonl"
|
| 57 |
+
logging.basicConfig(filename=log_path, level=logging.INFO, format="%(asctime)s %(levelname)s %(message)s", force=True)
|
| 58 |
+
|
| 59 |
+
candidates = [r for r in latest_records(args.source).values() if r.get("status") == "failed" and recoverable(r.get("error"))]
|
| 60 |
+
candidates.sort(key=lambda r: (urlparse(r["url"]).netloc.lower(), r["url"]))
|
| 61 |
+
if args.limit is not None:
|
| 62 |
+
candidates = candidates[:args.limit]
|
| 63 |
+
checkpoint = latest_records(state_path) if state_path.exists() and not args.restart else {}
|
| 64 |
+
pending = [r for r in candidates if r["url"] not in checkpoint]
|
| 65 |
+
|
| 66 |
+
downloader.ATTEMPTS = args.attempts
|
| 67 |
+
downloader.CONNECT_TIMEOUT = args.connect_timeout
|
| 68 |
+
downloader.MAX_TIME = args.max_time
|
| 69 |
+
downloader.domain_is_open = lambda _url: False
|
| 70 |
+
downloader.update_domain_health = lambda _url, _succeeded: None
|
| 71 |
+
existing = downloader.build_existing_index([primary_dir, overflow_dir])
|
| 72 |
+
minimum = int(args.min_free_gb * 1024 ** 3)
|
| 73 |
+
domain_locks = defaultdict(lambda: threading.BoundedSemaphore(1))
|
| 74 |
+
domain_last_request = defaultdict(float)
|
| 75 |
+
timing_lock = threading.Lock()
|
| 76 |
+
|
| 77 |
+
def retry(record):
|
| 78 |
+
domain = urlparse(record["url"]).netloc.lower()
|
| 79 |
+
with domain_locks[domain]:
|
| 80 |
+
with timing_lock:
|
| 81 |
+
wait = args.domain_delay - (time.monotonic() - domain_last_request[domain])
|
| 82 |
+
if wait > 0:
|
| 83 |
+
time.sleep(wait)
|
| 84 |
+
result = downloader.retry_one(record, primary_dir, overflow_dir, minimum, existing, True)
|
| 85 |
+
with timing_lock:
|
| 86 |
+
domain_last_request[domain] = time.monotonic()
|
| 87 |
+
return result
|
| 88 |
+
|
| 89 |
+
logging.info("prepared candidates=%s checkpoint=%s pending=%s", len(candidates), len(checkpoint), len(pending))
|
| 90 |
+
print(json.dumps({"candidates": len(candidates), "checkpoint": len(checkpoint), "pending": len(pending)}, ensure_ascii=False), flush=True)
|
| 91 |
+
mode = "w" if args.restart else "a"
|
| 92 |
+
ok = sum(r.get("status") == "ok" for r in checkpoint.values())
|
| 93 |
+
failed = sum(r.get("status") == "failed" for r in checkpoint.values())
|
| 94 |
+
started = time.time()
|
| 95 |
+
with state_path.open(mode, encoding="utf-8") as handle, ThreadPoolExecutor(max_workers=args.workers) as pool:
|
| 96 |
+
futures = [pool.submit(retry, record) for record in pending]
|
| 97 |
+
for index, future in enumerate(as_completed(futures), 1):
|
| 98 |
+
result = future.result()
|
| 99 |
+
if result.get("status") == "internal_error":
|
| 100 |
+
raise RuntimeError(result.get("error"))
|
| 101 |
+
checkpoint[result["url"]] = result
|
| 102 |
+
handle.write(json.dumps(result, ensure_ascii=False, separators=(",", ":")) + "\n")
|
| 103 |
+
handle.flush()
|
| 104 |
+
ok += result.get("status") == "ok"
|
| 105 |
+
failed += result.get("status") == "failed"
|
| 106 |
+
if index % 10 == 0 or index == len(pending):
|
| 107 |
+
speed = index / max(time.time() - started, 0.001)
|
| 108 |
+
logging.info("progress=%s/%s ok=%s failed=%s speed=%.3f records/s", len(checkpoint), len(candidates), ok, failed, speed)
|
| 109 |
+
print(json.dumps({"progress": len(checkpoint), "total": len(candidates), "ok": ok, "failed": failed, "speed": round(speed, 3)}), flush=True)
|
| 110 |
+
|
| 111 |
+
downloader.write_jsonl(output_path, checkpoint.values())
|
| 112 |
+
final = {"status": "complete", "candidates": len(candidates), "ok": ok, "failed": failed, "output": str(output_path)}
|
| 113 |
+
logging.info("complete %s", json.dumps(final, ensure_ascii=False))
|
| 114 |
+
print(json.dumps(final, ensure_ascii=False), flush=True)
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
if __name__ == "__main__":
|
| 118 |
+
main()
|
reddit/_rescue_20260917/raw/scripts/run_canonical_reddit_upload.ps1
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
$ErrorActionPreference = 'Stop'
|
| 2 |
+
|
| 3 |
+
$pythonExe = 'C:\Users\zong zilu\AppData\Local\Programs\Python\Python313\python.exe'
|
| 4 |
+
$uploader = 'D:\GeoAgent\Geo-CoT dataset\外网图像地理定位数据收集\reddit_posts\upload_reddit_images_batched.py'
|
| 5 |
+
$cacheRoot = 'C:\GeoAgent_hf_upload_cache\reddit\canonical_upload'
|
| 6 |
+
$nativeArgs = @(
|
| 7 |
+
$uploader
|
| 8 |
+
'upload'
|
| 9 |
+
'--cache-root'
|
| 10 |
+
$cacheRoot
|
| 11 |
+
'--revision'
|
| 12 |
+
'reddit'
|
| 13 |
+
'--communities'
|
| 14 |
+
'whereisthis'
|
| 15 |
+
'GeoPuzzle'
|
| 16 |
+
'PictureGame'
|
| 17 |
+
'--batch-size'
|
| 18 |
+
'10000'
|
| 19 |
+
'--max-batch-bytes'
|
| 20 |
+
'5368709120'
|
| 21 |
+
'--upload-threads'
|
| 22 |
+
'6'
|
| 23 |
+
'--request-timeout'
|
| 24 |
+
'180'
|
| 25 |
+
'--batch-retries'
|
| 26 |
+
'3'
|
| 27 |
+
'--retry-backoff-seconds'
|
| 28 |
+
'10'
|
| 29 |
+
'--rate-limit-poll-seconds'
|
| 30 |
+
'300'
|
| 31 |
+
'--heartbeat-seconds'
|
| 32 |
+
'30'
|
| 33 |
+
'--min-c-free-gib'
|
| 34 |
+
'5'
|
| 35 |
+
'--min-d-free-gib'
|
| 36 |
+
'2'
|
| 37 |
+
'--hard-c-floor-gib'
|
| 38 |
+
'1'
|
| 39 |
+
'--hard-d-floor-gib'
|
| 40 |
+
'2'
|
| 41 |
+
)
|
| 42 |
+
|
| 43 |
+
& $pythonExe @nativeArgs
|
| 44 |
+
$exitCode = $LASTEXITCODE
|
| 45 |
+
$statusPath = Join-Path $cacheRoot 'process_exit.json'
|
| 46 |
+
$payload = [ordered]@{
|
| 47 |
+
exited_at = [DateTimeOffset]::Now.ToUnixTimeSeconds()
|
| 48 |
+
exit_code = $exitCode
|
| 49 |
+
}
|
| 50 |
+
$payload | ConvertTo-Json | Set-Content -LiteralPath $statusPath -Encoding utf8
|
| 51 |
+
exit $exitCode
|
reddit/_rescue_20260917/raw/scripts/start_picturegame.ps1
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
$ErrorActionPreference = 'Stop'
|
| 2 |
+
|
| 3 |
+
$scriptPath = Join-Path $PSScriptRoot 'organize_three_communities.py'
|
| 4 |
+
$pythonExe = (Get-Command python.exe -ErrorAction Stop).Source
|
| 5 |
+
|
| 6 |
+
$psi = [System.Diagnostics.ProcessStartInfo]::new()
|
| 7 |
+
$psi.FileName = $pythonExe
|
| 8 |
+
$psi.WorkingDirectory = $PSScriptRoot
|
| 9 |
+
$psi.UseShellExecute = $false
|
| 10 |
+
$psi.CreateNoWindow = $true
|
| 11 |
+
$psi.RedirectStandardOutput = $false
|
| 12 |
+
$psi.RedirectStandardError = $false
|
| 13 |
+
$psi.ArgumentList.Add('-u')
|
| 14 |
+
$psi.ArgumentList.Add($scriptPath)
|
| 15 |
+
$psi.ArgumentList.Add('--communities')
|
| 16 |
+
$psi.ArgumentList.Add('PictureGame')
|
| 17 |
+
|
| 18 |
+
$process = [System.Diagnostics.Process]::Start($psi)
|
| 19 |
+
Write-Output ("started_pid=" + $process.Id)
|
reddit/_rescue_20260917/raw/scripts/start_retry_failed.ps1
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
$ErrorActionPreference = 'Stop'
|
| 2 |
+
|
| 3 |
+
$workDir = $PSScriptRoot
|
| 4 |
+
$pythonExe = (Get-Command python.exe -ErrorAction Stop).Source
|
| 5 |
+
$scriptPath = Join-Path $workDir 'retry_failed_images.py'
|
| 6 |
+
$stdoutPath = Join-Path $workDir 'retry_failed_runner.stdout.log'
|
| 7 |
+
$stderrPath = Join-Path $workDir 'retry_failed_runner.stderr.log'
|
| 8 |
+
|
| 9 |
+
$psi = [System.Diagnostics.ProcessStartInfo]::new()
|
| 10 |
+
$psi.FileName = $pythonExe
|
| 11 |
+
$psi.WorkingDirectory = $workDir
|
| 12 |
+
$psi.UseShellExecute = $false
|
| 13 |
+
$psi.CreateNoWindow = $true
|
| 14 |
+
$psi.RedirectStandardOutput = $false
|
| 15 |
+
$psi.RedirectStandardError = $false
|
| 16 |
+
$psi.ArgumentList.Add('-u')
|
| 17 |
+
$psi.ArgumentList.Add($scriptPath)
|
| 18 |
+
$process = [System.Diagnostics.Process]::Start($psi)
|
| 19 |
+
|
| 20 |
+
Write-Output ("started_pid=" + $process.Id)
|
reddit/_rescue_20260917/raw/scripts/test_upload_canonical_reddit_images.py
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Upload one canonical image per community in a single verified commit."""
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
import argparse
|
| 6 |
+
import json
|
| 7 |
+
import os
|
| 8 |
+
import shutil
|
| 9 |
+
import time
|
| 10 |
+
from pathlib import Path
|
| 11 |
+
|
| 12 |
+
# Configure direct networking before importing huggingface_hub, whose global
|
| 13 |
+
# client may otherwise retain the machine proxy settings.
|
| 14 |
+
for _proxy_key in ("HTTPS_PROXY", "HTTP_PROXY", "ALL_PROXY", "https_proxy", "http_proxy", "all_proxy"):
|
| 15 |
+
os.environ.pop(_proxy_key, None)
|
| 16 |
+
|
| 17 |
+
import httpx
|
| 18 |
+
from huggingface_hub import CommitOperationAdd, HfApi, set_client_factory
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
COMMUNITIES = ("whereisthis", "GeoPuzzle", "PictureGame")
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
def jsonl(path: Path):
|
| 25 |
+
with path.open("r", encoding="utf-8") as handle:
|
| 26 |
+
for line in handle:
|
| 27 |
+
if line.strip():
|
| 28 |
+
yield json.loads(line)
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
def configure_direct_client() -> None:
|
| 32 |
+
def factory() -> httpx.Client:
|
| 33 |
+
return httpx.Client(
|
| 34 |
+
follow_redirects=True,
|
| 35 |
+
trust_env=False,
|
| 36 |
+
timeout=httpx.Timeout(120.0, connect=30.0, pool=30.0),
|
| 37 |
+
)
|
| 38 |
+
set_client_factory(factory)
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
def retry_network(operation, label: str):
|
| 42 |
+
for attempt in range(1, 4):
|
| 43 |
+
try:
|
| 44 |
+
return operation()
|
| 45 |
+
except Exception as exc:
|
| 46 |
+
status = getattr(getattr(exc, "response", None), "status_code", None)
|
| 47 |
+
if status == 429:
|
| 48 |
+
raise RuntimeError(f"rate_limited_429 during {label}; stop and probe after 300 seconds") from exc
|
| 49 |
+
if attempt == 3:
|
| 50 |
+
raise
|
| 51 |
+
delay = 5 * (2 ** (attempt - 1))
|
| 52 |
+
print(f"network_retry label={label} attempt={attempt}/3 delay={delay}s error={type(exc).__name__}", flush=True)
|
| 53 |
+
time.sleep(delay)
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
def main() -> int:
|
| 57 |
+
parser = argparse.ArgumentParser()
|
| 58 |
+
parser.add_argument("--manifest", type=Path, required=True)
|
| 59 |
+
parser.add_argument("--naming-map", type=Path, required=True)
|
| 60 |
+
parser.add_argument("--state", type=Path, required=True)
|
| 61 |
+
args = parser.parse_args()
|
| 62 |
+
configure_direct_client()
|
| 63 |
+
free_c = shutil.disk_usage("C:\\").free
|
| 64 |
+
free_d = shutil.disk_usage("D:\\").free
|
| 65 |
+
if free_c < 5 * 1024**3 or free_d < 2 * 1024**3:
|
| 66 |
+
raise RuntimeError(f"storage floor reached: C={free_c} D={free_d}")
|
| 67 |
+
|
| 68 |
+
selected = {}
|
| 69 |
+
for row in jsonl(args.manifest):
|
| 70 |
+
if row["community"] in COMMUNITIES and row["status"] == "valid" and row["is_canonical"] and row["community"] not in selected:
|
| 71 |
+
selected[row["community"]] = row
|
| 72 |
+
if set(selected) != set(COMMUNITIES):
|
| 73 |
+
raise RuntimeError(f"missing test community: {set(COMMUNITIES) - set(selected)}")
|
| 74 |
+
invalid_names = [row["canonical_path"] for row in selected.values() if "_unlinked_" in row["canonical_path"]]
|
| 75 |
+
if invalid_names:
|
| 76 |
+
raise RuntimeError(f"unlinked canonical names are forbidden: {invalid_names}")
|
| 77 |
+
source_by_old = {}
|
| 78 |
+
for row in jsonl(args.naming_map):
|
| 79 |
+
source_by_old[row["old_remote_path"]] = row["local_path"]
|
| 80 |
+
|
| 81 |
+
api = HfApi()
|
| 82 |
+
revision = "reddit"
|
| 83 |
+
repo_id = "Geo-Club/Geo-Video"
|
| 84 |
+
operations = []
|
| 85 |
+
results = []
|
| 86 |
+
for community in COMMUNITIES:
|
| 87 |
+
row = selected[community]
|
| 88 |
+
source = Path(source_by_old[row["original_path"]])
|
| 89 |
+
if not source.is_file() or source.stat().st_size != row["size"]:
|
| 90 |
+
raise RuntimeError(f"source missing/changed: {source}")
|
| 91 |
+
exists_before = retry_network(
|
| 92 |
+
lambda row=row: api.file_exists(repo_id=repo_id, filename=row["canonical_path"], repo_type="dataset", revision=revision),
|
| 93 |
+
f"exists_before:{community}",
|
| 94 |
+
)
|
| 95 |
+
if not exists_before:
|
| 96 |
+
operations.append(CommitOperationAdd(path_in_repo=row["canonical_path"], path_or_fileobj=str(source)))
|
| 97 |
+
results.append({"community": community, "source": str(source), "remote_path": row["canonical_path"], "size": row["size"], "sha256": row["sha256"], "exists_before": exists_before})
|
| 98 |
+
commit_sha = None
|
| 99 |
+
if operations:
|
| 100 |
+
info = retry_network(
|
| 101 |
+
lambda: api.create_commit(repo_id=repo_id, repo_type="dataset", revision=revision, operations=operations, commit_message="Test canonical Reddit image paths (3 communities)"),
|
| 102 |
+
"create_test_commit",
|
| 103 |
+
)
|
| 104 |
+
commit_sha = info.oid
|
| 105 |
+
for row in results:
|
| 106 |
+
row["exists_after"] = retry_network(
|
| 107 |
+
lambda row=row: api.file_exists(repo_id=repo_id, filename=row["remote_path"], repo_type="dataset", revision=revision),
|
| 108 |
+
f"exists_after:{row['community']}",
|
| 109 |
+
)
|
| 110 |
+
passed = all(x["exists_after"] for x in results)
|
| 111 |
+
payload = {
|
| 112 |
+
"status": "passed" if passed else "failed",
|
| 113 |
+
"created_at": time.time(),
|
| 114 |
+
"repo_id": repo_id,
|
| 115 |
+
"revision": revision,
|
| 116 |
+
"commit_sha": commit_sha,
|
| 117 |
+
"operations": len(operations),
|
| 118 |
+
"local_image_copies_created": 0,
|
| 119 |
+
"c_free_gib": round(shutil.disk_usage("C:\\").free / 1024**3, 2),
|
| 120 |
+
"d_free_gib": round(shutil.disk_usage("D:\\").free / 1024**3, 2),
|
| 121 |
+
"files": results,
|
| 122 |
+
}
|
| 123 |
+
args.state.parent.mkdir(parents=True, exist_ok=True)
|
| 124 |
+
args.state.write_text(json.dumps(payload, ensure_ascii=False, indent=2), encoding="utf-8")
|
| 125 |
+
print(json.dumps(payload, ensure_ascii=False), flush=True)
|
| 126 |
+
return 0 if passed else 2
|
| 127 |
+
|
| 128 |
+
|
| 129 |
+
if __name__ == "__main__":
|
| 130 |
+
raise SystemExit(main())
|
reddit/_rescue_20260917/raw/scripts/upload_reddit_images_batched.py
ADDED
|
@@ -0,0 +1,1012 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Batch-upload already downloaded Reddit images to Hugging Face.
|
| 2 |
+
|
| 3 |
+
The source image directories are read in place and are never moved, renamed,
|
| 4 |
+
or modified. Only inventory, state, manifests, and logs are written below the
|
| 5 |
+
C: drive cache directory.
|
| 6 |
+
"""
|
| 7 |
+
|
| 8 |
+
from __future__ import annotations
|
| 9 |
+
|
| 10 |
+
import argparse
|
| 11 |
+
import hashlib
|
| 12 |
+
import json
|
| 13 |
+
import logging
|
| 14 |
+
import os
|
| 15 |
+
import shutil
|
| 16 |
+
import sys
|
| 17 |
+
import threading
|
| 18 |
+
import time
|
| 19 |
+
import uuid
|
| 20 |
+
from collections import Counter
|
| 21 |
+
from pathlib import Path
|
| 22 |
+
|
| 23 |
+
os.environ.setdefault("HF_HUB_DISABLE_PROGRESS_BARS", "1")
|
| 24 |
+
os.environ.setdefault("HF_HUB_DISABLE_XET", "1")
|
| 25 |
+
|
| 26 |
+
# Long uploads on this machine are more reliable over a direct connection.
|
| 27 |
+
# This changes only the uploader process, not the user's system settings.
|
| 28 |
+
for _proxy_var in (
|
| 29 |
+
"HTTPS_PROXY",
|
| 30 |
+
"HTTP_PROXY",
|
| 31 |
+
"ALL_PROXY",
|
| 32 |
+
"https_proxy",
|
| 33 |
+
"http_proxy",
|
| 34 |
+
"all_proxy",
|
| 35 |
+
):
|
| 36 |
+
os.environ.pop(_proxy_var, None)
|
| 37 |
+
|
| 38 |
+
# The machine-wide HTTPS proxy has repeatedly dropped long S3 PUT requests.
|
| 39 |
+
# Both endpoints are directly reachable, so bypass the proxy only for this
|
| 40 |
+
# uploader process while leaving the user's system proxy untouched.
|
| 41 |
+
_direct_hosts = "huggingface.co,.huggingface.co,amazonaws.com,.amazonaws.com"
|
| 42 |
+
for _proxy_var in ("NO_PROXY", "no_proxy"):
|
| 43 |
+
_existing_no_proxy = os.environ.get(_proxy_var, "")
|
| 44 |
+
_entries = [entry.strip() for entry in _existing_no_proxy.split(",") if entry.strip()]
|
| 45 |
+
for _host in _direct_hosts.split(","):
|
| 46 |
+
if _host not in _entries:
|
| 47 |
+
_entries.append(_host)
|
| 48 |
+
os.environ[_proxy_var] = ",".join(_entries)
|
| 49 |
+
|
| 50 |
+
import httpx
|
| 51 |
+
from huggingface_hub import CommitOperationAdd, HfApi, hf_hub_url, set_client_factory
|
| 52 |
+
from huggingface_hub.utils._http import default_client_factory
|
| 53 |
+
from huggingface_hub.utils import HfHubHTTPError
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
DEFAULT_REPO_ID = "Geo-Club/Geo-Video"
|
| 57 |
+
DEFAULT_REVISION = "reddit"
|
| 58 |
+
DEFAULT_SOURCE_ROOT = Path(
|
| 59 |
+
r"D:\GeoAgent\Geo-CoT dataset\外网图像地理定位数据收集\reddit_posts\solved_communities"
|
| 60 |
+
)
|
| 61 |
+
DEFAULT_OVERFLOW_ROOT = Path(r"C:\GeoAgent_reddit_overflow\solved_communities")
|
| 62 |
+
DEFAULT_CACHE_ROOT = Path(r"C:\GeoAgent_hf_upload_cache\reddit")
|
| 63 |
+
COMMUNITIES = ("whereisthis", "GeoPuzzle", "PictureGame")
|
| 64 |
+
# Hugging Face limits the number of files in a single repository directory.
|
| 65 |
+
# Keep a safety margin below the hard 10,000-file limit.
|
| 66 |
+
REMOTE_SHARD_SIZE = 9000
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
def configure_http_client(timeout_seconds: float) -> None:
|
| 70 |
+
"""Replace huggingface_hub's unbounded default timeout."""
|
| 71 |
+
|
| 72 |
+
def factory() -> httpx.Client:
|
| 73 |
+
return httpx.Client(
|
| 74 |
+
follow_redirects=True,
|
| 75 |
+
trust_env=False,
|
| 76 |
+
timeout=httpx.Timeout(
|
| 77 |
+
timeout_seconds,
|
| 78 |
+
connect=min(timeout_seconds, 30.0),
|
| 79 |
+
pool=min(timeout_seconds, 30.0),
|
| 80 |
+
),
|
| 81 |
+
)
|
| 82 |
+
|
| 83 |
+
set_client_factory(factory)
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
def setup_logging(cache_root: Path, verbose: bool = False) -> logging.Logger:
|
| 87 |
+
cache_root.mkdir(parents=True, exist_ok=True)
|
| 88 |
+
logger = logging.getLogger("reddit_hf_upload")
|
| 89 |
+
logger.setLevel(logging.DEBUG)
|
| 90 |
+
logger.handlers.clear()
|
| 91 |
+
formatter = logging.Formatter("%(asctime)s %(levelname)s %(message)s")
|
| 92 |
+
file_handler = logging.FileHandler(cache_root / "upload.log", encoding="utf-8")
|
| 93 |
+
file_handler.setFormatter(formatter)
|
| 94 |
+
file_handler.setLevel(logging.DEBUG)
|
| 95 |
+
console_handler = logging.StreamHandler(sys.stdout)
|
| 96 |
+
console_handler.setFormatter(formatter)
|
| 97 |
+
console_handler.setLevel(logging.DEBUG if verbose else logging.INFO)
|
| 98 |
+
logger.addHandler(file_handler)
|
| 99 |
+
logger.addHandler(console_handler)
|
| 100 |
+
return logger
|
| 101 |
+
|
| 102 |
+
|
| 103 |
+
def acquire_upload_lock(cache_root: Path, logger: logging.Logger):
|
| 104 |
+
"""Acquire the uploader singleton lock without deleting unknown locks."""
|
| 105 |
+
cache_root.mkdir(parents=True, exist_ok=True)
|
| 106 |
+
lock_path = cache_root / "upload.lock"
|
| 107 |
+
token = uuid.uuid4().hex
|
| 108 |
+
payload = {
|
| 109 |
+
"pid": os.getpid(),
|
| 110 |
+
"started_at": time.time(),
|
| 111 |
+
"token": token,
|
| 112 |
+
"command": "upload",
|
| 113 |
+
}
|
| 114 |
+
try:
|
| 115 |
+
handle = lock_path.open("x", encoding="utf-8")
|
| 116 |
+
except FileExistsError:
|
| 117 |
+
details = None
|
| 118 |
+
try:
|
| 119 |
+
details = json.loads(lock_path.read_text(encoding="utf-8"))
|
| 120 |
+
except Exception as exc:
|
| 121 |
+
logger.error(
|
| 122 |
+
"upload_lock_refused path=%s reason=unreadable_existing_lock error=%s",
|
| 123 |
+
lock_path,
|
| 124 |
+
exc,
|
| 125 |
+
)
|
| 126 |
+
raise RuntimeError(f"Cannot verify existing upload lock: {lock_path}") from exc
|
| 127 |
+
owner_pid = details.get("pid")
|
| 128 |
+
owner_alive = False
|
| 129 |
+
if isinstance(owner_pid, int) and owner_pid > 0:
|
| 130 |
+
try:
|
| 131 |
+
os.kill(owner_pid, 0)
|
| 132 |
+
owner_alive = True
|
| 133 |
+
except ProcessLookupError:
|
| 134 |
+
owner_alive = False
|
| 135 |
+
except PermissionError:
|
| 136 |
+
# Access denied still proves that a Windows process owns the PID.
|
| 137 |
+
owner_alive = True
|
| 138 |
+
except OSError:
|
| 139 |
+
owner_alive = False
|
| 140 |
+
if owner_alive:
|
| 141 |
+
logger.error(
|
| 142 |
+
"upload_lock_refused path=%s reason=active_owner owner_pid=%s started_at=%s",
|
| 143 |
+
lock_path,
|
| 144 |
+
owner_pid,
|
| 145 |
+
details.get("started_at"),
|
| 146 |
+
)
|
| 147 |
+
raise RuntimeError(f"Another uploader is active (pid={owner_pid})")
|
| 148 |
+
logger.error(
|
| 149 |
+
"upload_lock_refused path=%s reason=stale_or_unverifiable_lock owner_pid=%s started_at=%s action=manual_review_required",
|
| 150 |
+
lock_path,
|
| 151 |
+
owner_pid,
|
| 152 |
+
details.get("started_at"),
|
| 153 |
+
)
|
| 154 |
+
raise RuntimeError(f"Stale or unverifiable upload lock requires manual review: {lock_path}")
|
| 155 |
+
except OSError as exc:
|
| 156 |
+
logger.error("upload_lock_refused path=%s reason=create_failed error=%s", lock_path, exc)
|
| 157 |
+
raise
|
| 158 |
+
|
| 159 |
+
try:
|
| 160 |
+
try:
|
| 161 |
+
handle.write(json.dumps(payload, ensure_ascii=False, separators=(",", ":")))
|
| 162 |
+
handle.flush()
|
| 163 |
+
os.fsync(handle.fileno())
|
| 164 |
+
finally:
|
| 165 |
+
handle.close()
|
| 166 |
+
except Exception:
|
| 167 |
+
try:
|
| 168 |
+
lock_path.unlink()
|
| 169 |
+
except OSError:
|
| 170 |
+
logger.exception("upload_lock_cleanup_failed path=%s", lock_path)
|
| 171 |
+
raise
|
| 172 |
+
logger.info("upload_lock_acquired path=%s pid=%s", lock_path, os.getpid())
|
| 173 |
+
|
| 174 |
+
def release() -> None:
|
| 175 |
+
try:
|
| 176 |
+
current = json.loads(lock_path.read_text(encoding="utf-8"))
|
| 177 |
+
except Exception:
|
| 178 |
+
logger.warning("upload_lock_preserved path=%s reason=ownership_check_failed", lock_path)
|
| 179 |
+
return
|
| 180 |
+
if current.get("token") != token or current.get("pid") != os.getpid():
|
| 181 |
+
logger.warning("upload_lock_preserved path=%s reason=ownership_mismatch", lock_path)
|
| 182 |
+
return
|
| 183 |
+
try:
|
| 184 |
+
lock_path.unlink()
|
| 185 |
+
logger.info("upload_lock_released path=%s", lock_path)
|
| 186 |
+
except FileNotFoundError:
|
| 187 |
+
pass
|
| 188 |
+
except OSError:
|
| 189 |
+
logger.exception("upload_lock_release_failed path=%s", lock_path)
|
| 190 |
+
|
| 191 |
+
return release
|
| 192 |
+
|
| 193 |
+
|
| 194 |
+
def append_jsonl(path: Path, record: dict) -> None:
|
| 195 |
+
with path.open("a", encoding="utf-8") as handle:
|
| 196 |
+
handle.write(json.dumps(record, ensure_ascii=False, separators=(",", ":")) + "\n")
|
| 197 |
+
|
| 198 |
+
|
| 199 |
+
def read_jsonl(path: Path):
|
| 200 |
+
if not path.exists():
|
| 201 |
+
return
|
| 202 |
+
with path.open("r", encoding="utf-8") as handle:
|
| 203 |
+
for line_number, line in enumerate(handle, 1):
|
| 204 |
+
if not line.strip():
|
| 205 |
+
continue
|
| 206 |
+
try:
|
| 207 |
+
yield json.loads(line)
|
| 208 |
+
except json.JSONDecodeError:
|
| 209 |
+
logging.getLogger("reddit_hf_upload").warning(
|
| 210 |
+
"skip_invalid_json path=%s line=%s", path, line_number
|
| 211 |
+
)
|
| 212 |
+
|
| 213 |
+
|
| 214 |
+
def image_files(root: Path, community: str) -> list[Path]:
|
| 215 |
+
image_root = root / community / "images"
|
| 216 |
+
if not image_root.exists():
|
| 217 |
+
return []
|
| 218 |
+
return sorted(
|
| 219 |
+
path
|
| 220 |
+
for path in image_root.rglob("*")
|
| 221 |
+
if path.is_file() and not path.name.endswith(".part") and path.stat().st_size > 0
|
| 222 |
+
)
|
| 223 |
+
|
| 224 |
+
|
| 225 |
+
def sha256_file(path: Path, chunk_size: int = 1024 * 1024) -> str:
|
| 226 |
+
digest = hashlib.sha256()
|
| 227 |
+
with path.open("rb") as handle:
|
| 228 |
+
while chunk := handle.read(chunk_size):
|
| 229 |
+
digest.update(chunk)
|
| 230 |
+
return digest.hexdigest()
|
| 231 |
+
|
| 232 |
+
|
| 233 |
+
def build_inventory(args, logger: logging.Logger) -> list[dict]:
|
| 234 |
+
inventory_path = args.cache_root / "inventory.jsonl"
|
| 235 |
+
temp_path = inventory_path.with_suffix(".jsonl.part")
|
| 236 |
+
records: list[dict] = []
|
| 237 |
+
seen: dict[tuple[str, str], dict] = {}
|
| 238 |
+
source_roots = [args.source_root, args.overflow_root]
|
| 239 |
+
|
| 240 |
+
logger.info("inventory_start source_roots=%s", [str(root) for root in source_roots])
|
| 241 |
+
for community in args.communities:
|
| 242 |
+
discovered = 0
|
| 243 |
+
for root in source_roots:
|
| 244 |
+
for path in image_files(root, community):
|
| 245 |
+
discovered += 1
|
| 246 |
+
key = (community, path.name)
|
| 247 |
+
record = {
|
| 248 |
+
"community": community,
|
| 249 |
+
"filename": path.name,
|
| 250 |
+
"local_path": str(path),
|
| 251 |
+
"relative_path": None,
|
| 252 |
+
"legacy_relative_path": f"reddit/images/{community}/{path.name}",
|
| 253 |
+
"size": path.stat().st_size,
|
| 254 |
+
"sha256": None,
|
| 255 |
+
}
|
| 256 |
+
previous = seen.get(key)
|
| 257 |
+
if previous is None:
|
| 258 |
+
seen[key] = record
|
| 259 |
+
elif previous["size"] != record["size"]:
|
| 260 |
+
logger.error(
|
| 261 |
+
"duplicate_target_conflict community=%s filename=%s first=%s second=%s",
|
| 262 |
+
community,
|
| 263 |
+
path.name,
|
| 264 |
+
previous["local_path"],
|
| 265 |
+
path,
|
| 266 |
+
)
|
| 267 |
+
else:
|
| 268 |
+
logger.warning(
|
| 269 |
+
"duplicate_target_same_size community=%s filename=%s skipped=%s",
|
| 270 |
+
community,
|
| 271 |
+
path.name,
|
| 272 |
+
path,
|
| 273 |
+
)
|
| 274 |
+
logger.info("inventory_community community=%s discovered=%s", community, discovered)
|
| 275 |
+
|
| 276 |
+
records = [seen[key] for key in sorted(seen)]
|
| 277 |
+
# Assign shards from the stable filename order. Rebuilding the inventory
|
| 278 |
+
# therefore produces the same remote path on every resume.
|
| 279 |
+
for community in args.communities:
|
| 280 |
+
community_records = [record for record in records if record["community"] == community]
|
| 281 |
+
for index, record in enumerate(community_records):
|
| 282 |
+
shard = index // REMOTE_SHARD_SIZE
|
| 283 |
+
record["shard"] = shard
|
| 284 |
+
record["relative_path"] = (
|
| 285 |
+
f"reddit/images/{community}/{shard:04d}/{record['filename']}"
|
| 286 |
+
)
|
| 287 |
+
with temp_path.open("w", encoding="utf-8") as handle:
|
| 288 |
+
for record in records:
|
| 289 |
+
handle.write(json.dumps(record, ensure_ascii=False, separators=(",", ":")) + "\n")
|
| 290 |
+
temp_path.replace(inventory_path)
|
| 291 |
+
summary = Counter(record["community"] for record in records)
|
| 292 |
+
total_bytes = sum(record["size"] for record in records)
|
| 293 |
+
summary_record = {
|
| 294 |
+
"created_at": time.time(),
|
| 295 |
+
"records": len(records),
|
| 296 |
+
"bytes": total_bytes,
|
| 297 |
+
"gib": round(total_bytes / (1024**3), 3),
|
| 298 |
+
"communities": dict(summary),
|
| 299 |
+
}
|
| 300 |
+
(args.cache_root / "inventory_summary.json").write_text(
|
| 301 |
+
json.dumps(summary_record, ensure_ascii=False, indent=2), encoding="utf-8"
|
| 302 |
+
)
|
| 303 |
+
logger.info(
|
| 304 |
+
"inventory_complete records=%s bytes=%s gib=%.3f communities=%s",
|
| 305 |
+
len(records),
|
| 306 |
+
total_bytes,
|
| 307 |
+
total_bytes / (1024**3),
|
| 308 |
+
dict(summary),
|
| 309 |
+
)
|
| 310 |
+
return records
|
| 311 |
+
|
| 312 |
+
|
| 313 |
+
def load_inventory(args, logger: logging.Logger) -> list[dict]:
|
| 314 |
+
path = args.cache_root / "inventory.jsonl"
|
| 315 |
+
if not path.exists() or args.rebuild_inventory:
|
| 316 |
+
return build_inventory(args, logger)
|
| 317 |
+
records = list(read_jsonl(path))
|
| 318 |
+
logger.info("inventory_loaded records=%s path=%s", len(records), path)
|
| 319 |
+
return records
|
| 320 |
+
|
| 321 |
+
|
| 322 |
+
def load_latest_state(args) -> dict[str, dict]:
|
| 323 |
+
latest: dict[str, dict] = {}
|
| 324 |
+
for record in read_jsonl(args.cache_root / "upload_state.jsonl") or ():
|
| 325 |
+
remote_path = record.get("remote_path") or record.get("relative_path")
|
| 326 |
+
if remote_path:
|
| 327 |
+
latest[remote_path] = record
|
| 328 |
+
return latest
|
| 329 |
+
|
| 330 |
+
|
| 331 |
+
def remote_file_sizes(api: HfApi, args, logger: logging.Logger) -> dict[str, int]:
|
| 332 |
+
for attempt in range(1, args.batch_retries + 1):
|
| 333 |
+
try:
|
| 334 |
+
entries = api.list_repo_tree(
|
| 335 |
+
args.repo_id,
|
| 336 |
+
path_in_repo="reddit/images",
|
| 337 |
+
recursive=True,
|
| 338 |
+
revision=args.revision,
|
| 339 |
+
repo_type="dataset",
|
| 340 |
+
)
|
| 341 |
+
# This huggingface_hub version returns ``type=None`` for both files
|
| 342 |
+
# and folders; file entries expose a numeric size.
|
| 343 |
+
files = {
|
| 344 |
+
entry.path: int(entry.size)
|
| 345 |
+
for entry in entries
|
| 346 |
+
if getattr(entry, "size", None) is not None
|
| 347 |
+
}
|
| 348 |
+
logger.info("remote_inventory_complete files=%s bytes=%s", len(files), sum(files.values()))
|
| 349 |
+
return files
|
| 350 |
+
except Exception as exc:
|
| 351 |
+
# A missing directory is normal before the first image commit.
|
| 352 |
+
status_code = getattr(getattr(exc, "response", None), "status_code", None)
|
| 353 |
+
if exc.__class__.__name__ == "RemoteEntryNotFoundError" or status_code == 404:
|
| 354 |
+
logger.info("remote_inventory_empty path=reddit/images")
|
| 355 |
+
return {}
|
| 356 |
+
if attempt >= args.batch_retries:
|
| 357 |
+
logger.error("remote_inventory_failed attempts=%s error=%s", attempt, exc)
|
| 358 |
+
raise
|
| 359 |
+
delay = args.retry_backoff_seconds * (2 ** (attempt - 1))
|
| 360 |
+
logger.warning(
|
| 361 |
+
"remote_inventory_retry attempt=%s/%s delay_seconds=%.1f error=%s",
|
| 362 |
+
attempt,
|
| 363 |
+
args.batch_retries,
|
| 364 |
+
delay,
|
| 365 |
+
f"{type(exc).__name__}: {exc}"[-500:],
|
| 366 |
+
)
|
| 367 |
+
time.sleep(delay)
|
| 368 |
+
|
| 369 |
+
|
| 370 |
+
def remote_files(api: HfApi, args, logger: logging.Logger) -> set[str]:
|
| 371 |
+
return set(remote_file_sizes(api, args, logger))
|
| 372 |
+
|
| 373 |
+
|
| 374 |
+
def manifest_remote_path(record: dict, remote_sizes: dict[str, int]) -> str:
|
| 375 |
+
"""Prefer an existing legacy path, otherwise use the sharded path."""
|
| 376 |
+
legacy = record["legacy_relative_path"]
|
| 377 |
+
current = record["relative_path"]
|
| 378 |
+
if remote_sizes.get(legacy) == record["size"]:
|
| 379 |
+
return legacy
|
| 380 |
+
return current
|
| 381 |
+
|
| 382 |
+
|
| 383 |
+
def classify_error(exc: Exception) -> str:
|
| 384 |
+
status_code = getattr(getattr(exc, "response", None), "status_code", None)
|
| 385 |
+
text = f"{type(exc).__name__}: {exc}".lower()
|
| 386 |
+
if status_code == 429:
|
| 387 |
+
return "rate_limit_429"
|
| 388 |
+
if status_code in (401, 403):
|
| 389 |
+
return "permission_401_403"
|
| 390 |
+
if status_code == 404:
|
| 391 |
+
return "remote_404"
|
| 392 |
+
if status_code is not None and 500 <= status_code <= 599:
|
| 393 |
+
return "server_5xx"
|
| 394 |
+
if "timeout" in text or "timed out" in text:
|
| 395 |
+
return "connection_timeout"
|
| 396 |
+
if any(token in text for token in ("tls", "ssl", "certificate", "proxy")):
|
| 397 |
+
return "tls_or_proxy"
|
| 398 |
+
if any(token in text for token in ("size", "path", "filename")):
|
| 399 |
+
return "file_size_or_path"
|
| 400 |
+
return "network_or_unknown"
|
| 401 |
+
|
| 402 |
+
|
| 403 |
+
def storage_snapshot(args) -> dict[str, float]:
|
| 404 |
+
return {
|
| 405 |
+
"c_free_gib": shutil.disk_usage(args.cache_root.anchor or "C:\\").free / (1024**3),
|
| 406 |
+
"d_free_gib": shutil.disk_usage(args.source_root.anchor or "D:\\").free / (1024**3),
|
| 407 |
+
}
|
| 408 |
+
|
| 409 |
+
|
| 410 |
+
def storage_is_safe(args, logger: logging.Logger) -> bool:
|
| 411 |
+
snapshot = storage_snapshot(args)
|
| 412 |
+
safe = (
|
| 413 |
+
snapshot["c_free_gib"] >= args.min_c_free_gib
|
| 414 |
+
and snapshot["d_free_gib"] >= args.min_d_free_gib
|
| 415 |
+
)
|
| 416 |
+
logger.info(
|
| 417 |
+
"storage_check c_free_gib=%.2f d_free_gib=%.2f safe=%s thresholds=%.1f/%.1f",
|
| 418 |
+
snapshot["c_free_gib"],
|
| 419 |
+
snapshot["d_free_gib"],
|
| 420 |
+
int(safe),
|
| 421 |
+
args.min_c_free_gib,
|
| 422 |
+
args.min_d_free_gib,
|
| 423 |
+
)
|
| 424 |
+
return safe
|
| 425 |
+
|
| 426 |
+
|
| 427 |
+
def storage_at_hard_floor(args, logger: logging.Logger) -> bool:
|
| 428 |
+
"""Return true only when the hard stop floor is crossed."""
|
| 429 |
+
snapshot = storage_snapshot(args)
|
| 430 |
+
hard_stop = (
|
| 431 |
+
snapshot["c_free_gib"] < args.hard_c_floor_gib
|
| 432 |
+
or snapshot["d_free_gib"] < args.hard_d_floor_gib
|
| 433 |
+
)
|
| 434 |
+
logger.info(
|
| 435 |
+
"storage_hard_floor_check c_free_gib=%.2f d_free_gib=%.2f hard_stop=%s floors=%.1f/%.1f",
|
| 436 |
+
snapshot["c_free_gib"], snapshot["d_free_gib"], int(hard_stop),
|
| 437 |
+
args.hard_c_floor_gib, args.hard_d_floor_gib,
|
| 438 |
+
)
|
| 439 |
+
return hard_stop
|
| 440 |
+
|
| 441 |
+
|
| 442 |
+
def cleanup_rebuildable_batch_cache(args, logger: logging.Logger) -> int:
|
| 443 |
+
"""Remove only uploader-owned, rebuildable temporary files.
|
| 444 |
+
|
| 445 |
+
Images, inventories, state, manifests, and logs are deliberately excluded.
|
| 446 |
+
The uploader currently streams source files directly, so this is normally a
|
| 447 |
+
no-op, but it also handles interrupted future/library staging safely.
|
| 448 |
+
"""
|
| 449 |
+
removed_bytes = 0
|
| 450 |
+
removed_files = 0
|
| 451 |
+
allowed_suffixes = {".part", ".tmp"}
|
| 452 |
+
rebuildable_names = {"large_folder_console_error.log"}
|
| 453 |
+
for path in args.cache_root.rglob("*"):
|
| 454 |
+
if not path.is_file() or path.name in {
|
| 455 |
+
"inventory.jsonl", "inventory_summary.json", "upload_state.jsonl",
|
| 456 |
+
"upload.log", "manifest_remote.jsonl", "manifest_remote_summary.json",
|
| 457 |
+
}:
|
| 458 |
+
continue
|
| 459 |
+
if path.suffix.lower() not in allowed_suffixes and path.name not in rebuildable_names:
|
| 460 |
+
continue
|
| 461 |
+
try:
|
| 462 |
+
size = path.stat().st_size
|
| 463 |
+
path.unlink()
|
| 464 |
+
removed_bytes += size
|
| 465 |
+
removed_files += 1
|
| 466 |
+
logger.info("batch_cache_removed path=%s bytes=%s", path, size)
|
| 467 |
+
except FileNotFoundError:
|
| 468 |
+
continue
|
| 469 |
+
except OSError as exc:
|
| 470 |
+
logger.warning("batch_cache_remove_failed path=%s error=%s", path, exc)
|
| 471 |
+
logger.info(
|
| 472 |
+
"batch_cache_cleanup_complete files=%s bytes=%s gib=%.3f",
|
| 473 |
+
removed_files, removed_bytes, removed_bytes / (1024**3),
|
| 474 |
+
)
|
| 475 |
+
return removed_files
|
| 476 |
+
|
| 477 |
+
|
| 478 |
+
def wait_for_storage_recovery(args, logger: logging.Logger, reason: str) -> None:
|
| 479 |
+
"""Keep the process alive until storage reaches the recovery watermark."""
|
| 480 |
+
cleanup_rebuildable_batch_cache(args, logger)
|
| 481 |
+
recovery_c = args.min_c_free_gib + args.storage_recovery_buffer_gib
|
| 482 |
+
recovery_d = args.min_d_free_gib + args.storage_recovery_buffer_gib
|
| 483 |
+
logger.warning(
|
| 484 |
+
"upload_waiting_for_storage reason=%s recovery_thresholds=%.2f/%.2f check_seconds=%.0f",
|
| 485 |
+
reason, recovery_c, recovery_d, args.storage_check_seconds,
|
| 486 |
+
)
|
| 487 |
+
while True:
|
| 488 |
+
snapshot = storage_snapshot(args)
|
| 489 |
+
recovered = (
|
| 490 |
+
snapshot["c_free_gib"] >= recovery_c
|
| 491 |
+
and snapshot["d_free_gib"] >= recovery_d
|
| 492 |
+
)
|
| 493 |
+
logger.info(
|
| 494 |
+
"storage_recovery_check c_free_gib=%.2f d_free_gib=%.2f recovered=%s",
|
| 495 |
+
snapshot["c_free_gib"], snapshot["d_free_gib"], int(recovered),
|
| 496 |
+
)
|
| 497 |
+
if recovered:
|
| 498 |
+
logger.info("storage_recovered action=resume_upload")
|
| 499 |
+
return
|
| 500 |
+
cleanup_rebuildable_batch_cache(args, logger)
|
| 501 |
+
time.sleep(args.storage_check_seconds)
|
| 502 |
+
|
| 503 |
+
|
| 504 |
+
def select_records(records: list[dict], args, latest: dict[str, dict], remote: set[str]) -> list[dict]:
|
| 505 |
+
candidates = []
|
| 506 |
+
for record in records:
|
| 507 |
+
if record["community"] not in args.communities:
|
| 508 |
+
continue
|
| 509 |
+
# Remote state is authoritative. A stale local "uploaded" record must
|
| 510 |
+
# not hide a file that is absent from the selected branch.
|
| 511 |
+
if record["relative_path"] in remote or record["legacy_relative_path"] in remote:
|
| 512 |
+
continue
|
| 513 |
+
candidates.append({**record, "upload_path": record["relative_path"]})
|
| 514 |
+
if args.test:
|
| 515 |
+
selected = []
|
| 516 |
+
for community in args.communities:
|
| 517 |
+
selected.extend([item for item in candidates if item["community"] == community][: args.test_per_community])
|
| 518 |
+
return selected
|
| 519 |
+
if args.limit is not None:
|
| 520 |
+
return candidates[: args.limit]
|
| 521 |
+
return candidates
|
| 522 |
+
|
| 523 |
+
|
| 524 |
+
def batched(records: list[dict], batch_size: int, max_batch_bytes: int):
|
| 525 |
+
batch: list[dict] = []
|
| 526 |
+
batch_bytes = 0
|
| 527 |
+
for record in records:
|
| 528 |
+
size = int(record["size"])
|
| 529 |
+
if batch and (len(batch) >= batch_size or batch_bytes + size > max_batch_bytes):
|
| 530 |
+
yield batch
|
| 531 |
+
batch = []
|
| 532 |
+
batch_bytes = 0
|
| 533 |
+
batch.append(record)
|
| 534 |
+
batch_bytes += size
|
| 535 |
+
if batch:
|
| 536 |
+
yield batch
|
| 537 |
+
|
| 538 |
+
|
| 539 |
+
def community_batched(
|
| 540 |
+
records: list[dict],
|
| 541 |
+
communities: tuple[str, ...],
|
| 542 |
+
batch_size: int,
|
| 543 |
+
max_batch_bytes: int,
|
| 544 |
+
):
|
| 545 |
+
"""Yield large directory-like batches without mixing communities."""
|
| 546 |
+
for community in communities:
|
| 547 |
+
community_records = [record for record in records if record["community"] == community]
|
| 548 |
+
for batch in batched(community_records, batch_size, max_batch_bytes):
|
| 549 |
+
yield community, batch
|
| 550 |
+
|
| 551 |
+
|
| 552 |
+
def estimate_batch_plan(
|
| 553 |
+
records: list[dict],
|
| 554 |
+
communities: tuple[str, ...],
|
| 555 |
+
batch_size: int,
|
| 556 |
+
max_batch_bytes: int,
|
| 557 |
+
) -> dict[str, dict[str, int]]:
|
| 558 |
+
"""Estimate commit count using the same rules as the actual batch planner."""
|
| 559 |
+
plan: dict[str, dict[str, int]] = {}
|
| 560 |
+
for community in communities:
|
| 561 |
+
community_records = [record for record in records if record["community"] == community]
|
| 562 |
+
batches = list(batched(community_records, batch_size, max_batch_bytes))
|
| 563 |
+
plan[community] = {
|
| 564 |
+
"files": len(community_records),
|
| 565 |
+
"bytes": sum(int(record["size"]) for record in community_records),
|
| 566 |
+
"batches": len(batches),
|
| 567 |
+
}
|
| 568 |
+
return plan
|
| 569 |
+
|
| 570 |
+
|
| 571 |
+
def test_batched(records: list[dict], max_batch_bytes: int):
|
| 572 |
+
"""Keep the three-file preflight in one commit while full batches stay isolated."""
|
| 573 |
+
if records:
|
| 574 |
+
yield "test-preflight", list(records)
|
| 575 |
+
|
| 576 |
+
|
| 577 |
+
def upload_batch(api: HfApi, args, logger: logging.Logger, batch: list[dict], batch_number: int, state_path: Path):
|
| 578 |
+
started = time.time()
|
| 579 |
+
operations = []
|
| 580 |
+
valid_records = []
|
| 581 |
+
invalid_count = 0
|
| 582 |
+
for record in batch:
|
| 583 |
+
path = Path(record["local_path"])
|
| 584 |
+
if not path.exists() or path.stat().st_size != record["size"]:
|
| 585 |
+
append_jsonl(state_path, {**record, "revision": args.revision, "status": "failed", "error_category": "source_file_404", "error": "source_changed_or_missing", "batch": batch_number})
|
| 586 |
+
logger.error("source_invalid category=source_file_404 community=%s filename=%s path=%s", record["community"], record["filename"], path)
|
| 587 |
+
invalid_count += 1
|
| 588 |
+
continue
|
| 589 |
+
operations.append(CommitOperationAdd(path_in_repo=record["upload_path"], path_or_fileobj=path))
|
| 590 |
+
valid_records.append(record)
|
| 591 |
+
if not operations:
|
| 592 |
+
return 0, invalid_count, 0.0, None, 0
|
| 593 |
+
|
| 594 |
+
commit_sha = None
|
| 595 |
+
last_error = None
|
| 596 |
+
ordinary_attempt = 0
|
| 597 |
+
rate_limit_count = 0
|
| 598 |
+
while True:
|
| 599 |
+
ordinary_attempt += 1
|
| 600 |
+
stop_heartbeat = threading.Event()
|
| 601 |
+
|
| 602 |
+
def heartbeat() -> None:
|
| 603 |
+
while not stop_heartbeat.wait(args.heartbeat_seconds):
|
| 604 |
+
logger.info(
|
| 605 |
+
"batch_heartbeat batch=%s attempt=%s files=%s bytes=%s elapsed=%.1fs",
|
| 606 |
+
batch_number,
|
| 607 |
+
ordinary_attempt,
|
| 608 |
+
len(operations),
|
| 609 |
+
sum(item["size"] for item in batch),
|
| 610 |
+
time.time() - started,
|
| 611 |
+
)
|
| 612 |
+
snapshot = storage_snapshot(args)
|
| 613 |
+
logger.info(
|
| 614 |
+
"batch_storage_heartbeat batch=%s c_free_gib=%.2f d_free_gib=%.2f",
|
| 615 |
+
batch_number,
|
| 616 |
+
snapshot["c_free_gib"],
|
| 617 |
+
snapshot["d_free_gib"],
|
| 618 |
+
)
|
| 619 |
+
|
| 620 |
+
heartbeat_thread = threading.Thread(target=heartbeat, daemon=True)
|
| 621 |
+
heartbeat_thread.start()
|
| 622 |
+
try:
|
| 623 |
+
logger.info(
|
| 624 |
+
"batch_start batch=%s attempt=%s/%s files=%s bytes=%s",
|
| 625 |
+
batch_number,
|
| 626 |
+
ordinary_attempt,
|
| 627 |
+
args.batch_retries,
|
| 628 |
+
len(operations),
|
| 629 |
+
sum(item["size"] for item in batch),
|
| 630 |
+
)
|
| 631 |
+
info = api.create_commit(
|
| 632 |
+
repo_id=args.repo_id,
|
| 633 |
+
operations=operations,
|
| 634 |
+
commit_message=f"Add Reddit images batch {batch_number:06d}",
|
| 635 |
+
repo_type="dataset",
|
| 636 |
+
revision=args.revision,
|
| 637 |
+
num_threads=args.upload_threads,
|
| 638 |
+
)
|
| 639 |
+
commit_sha = getattr(info, "oid", None)
|
| 640 |
+
last_error = None
|
| 641 |
+
break
|
| 642 |
+
except Exception as exc:
|
| 643 |
+
last_error = exc
|
| 644 |
+
status_code = getattr(getattr(exc, "response", None), "status_code", None)
|
| 645 |
+
category = classify_error(exc)
|
| 646 |
+
logger.warning(
|
| 647 |
+
"batch_attempt_failed batch=%s attempt=%s/%s category=%s error=%s",
|
| 648 |
+
batch_number,
|
| 649 |
+
ordinary_attempt,
|
| 650 |
+
args.batch_retries,
|
| 651 |
+
category,
|
| 652 |
+
f"{type(exc).__name__}: {exc}"[-1000:],
|
| 653 |
+
exc_info=True,
|
| 654 |
+
)
|
| 655 |
+
if status_code == 429:
|
| 656 |
+
rate_limit_count += 1
|
| 657 |
+
delay = args.rate_limit_poll_seconds
|
| 658 |
+
ordinary_attempt -= 1
|
| 659 |
+
logger.warning(
|
| 660 |
+
"commit_rate_limited batch=%s rate_limit_count=%s retry_is_not_permanent_failure=1 probe_in_seconds=%.0f server=%s",
|
| 661 |
+
batch_number,
|
| 662 |
+
rate_limit_count,
|
| 663 |
+
delay,
|
| 664 |
+
str(exc)[-500:],
|
| 665 |
+
)
|
| 666 |
+
elif ordinary_attempt < args.batch_retries:
|
| 667 |
+
delay = args.retry_backoff_seconds * (2 ** (ordinary_attempt - 1))
|
| 668 |
+
else:
|
| 669 |
+
delay = None
|
| 670 |
+
if delay is None:
|
| 671 |
+
break
|
| 672 |
+
logger.info("batch_retry_wait batch=%s seconds=%.1f", batch_number, delay)
|
| 673 |
+
time.sleep(delay)
|
| 674 |
+
if status_code == 429:
|
| 675 |
+
try:
|
| 676 |
+
api.repo_info(args.repo_id, repo_type="dataset", revision=args.revision)
|
| 677 |
+
logger.info("rate_limit_plan_only_probe batch=%s result=read_api_ok", batch_number)
|
| 678 |
+
except Exception as probe_exc:
|
| 679 |
+
logger.warning("rate_limit_plan_only_probe batch=%s result=failed error=%s", batch_number, str(probe_exc)[-500:])
|
| 680 |
+
finally:
|
| 681 |
+
stop_heartbeat.set()
|
| 682 |
+
heartbeat_thread.join(timeout=2)
|
| 683 |
+
|
| 684 |
+
if last_error is None and commit_sha:
|
| 685 |
+
elapsed = max(time.time() - started, 0.001)
|
| 686 |
+
speed = len(operations) / elapsed
|
| 687 |
+
for record in valid_records:
|
| 688 |
+
append_jsonl(state_path, {**record, "remote_path": record["upload_path"], "revision": args.revision, "status": "uploaded", "error_category": None, "error": None, "batch": batch_number, "commit_sha": commit_sha, "sha256": record.get("sha256") or sha256_file(Path(record["local_path"])), "uploaded_at": time.time()})
|
| 689 |
+
logger.info(
|
| 690 |
+
"batch_complete batch=%s community=%s files=%s failed=%s bytes=%s elapsed=%.1fs speed=%.2f files_per_sec commit=%s",
|
| 691 |
+
batch_number,
|
| 692 |
+
batch[0]["community"],
|
| 693 |
+
len(operations),
|
| 694 |
+
invalid_count,
|
| 695 |
+
sum(item["size"] for item in batch),
|
| 696 |
+
elapsed,
|
| 697 |
+
speed,
|
| 698 |
+
commit_sha,
|
| 699 |
+
)
|
| 700 |
+
return len(operations), invalid_count, speed, commit_sha, rate_limit_count
|
| 701 |
+
else:
|
| 702 |
+
elapsed = max(time.time() - started, 0.001)
|
| 703 |
+
category = classify_error(last_error)
|
| 704 |
+
error = f"{type(last_error).__name__}: {last_error}"[-1000:]
|
| 705 |
+
for record in valid_records:
|
| 706 |
+
append_jsonl(state_path, {**record, "remote_path": record["upload_path"], "revision": args.revision, "status": "failed", "error_category": category, "error": error, "batch": batch_number, "uploaded_at": time.time()})
|
| 707 |
+
logger.error("batch_failed batch=%s files=%s elapsed=%.1fs category=%s error=%s", batch_number, len(operations), elapsed, category, error)
|
| 708 |
+
return 0, len(operations) + invalid_count, 0.0, None, rate_limit_count
|
| 709 |
+
|
| 710 |
+
|
| 711 |
+
def upload(args, logger: logging.Logger) -> int:
|
| 712 |
+
records = load_inventory(args, logger)
|
| 713 |
+
api = HfApi()
|
| 714 |
+
logger.info(
|
| 715 |
+
"direct_source_mode enabled=1 image_staging=disabled cache_root=%s",
|
| 716 |
+
args.cache_root,
|
| 717 |
+
)
|
| 718 |
+
# The reddit branch already exists. Calling create_branch on every resume
|
| 719 |
+
# consumes the repository commit-rate budget and is unnecessary.
|
| 720 |
+
cleanup_rebuildable_batch_cache(args, logger)
|
| 721 |
+
if storage_at_hard_floor(args, logger):
|
| 722 |
+
logger.error("upload_stopped reason=hard_storage_floor_before_remote_query")
|
| 723 |
+
return 75
|
| 724 |
+
latest = load_latest_state(args)
|
| 725 |
+
remote = remote_files(api, args, logger)
|
| 726 |
+
selected = select_records(records, args, latest, remote)
|
| 727 |
+
total_bytes = sum(record["size"] for record in selected)
|
| 728 |
+
scoped_total = sum(1 for record in records if record["community"] in args.communities)
|
| 729 |
+
skipped = scoped_total - len(selected)
|
| 730 |
+
logger.info(
|
| 731 |
+
"upload_plan mode=%s revision=%s selected_files=%s skipped_remote=%s selected_gib=%.3f batch_size=%s max_batch_gib=%.3f",
|
| 732 |
+
"test" if args.test else "full",
|
| 733 |
+
args.revision,
|
| 734 |
+
len(selected),
|
| 735 |
+
skipped,
|
| 736 |
+
total_bytes / (1024**3),
|
| 737 |
+
args.batch_size,
|
| 738 |
+
args.max_batch_bytes / (1024**3),
|
| 739 |
+
)
|
| 740 |
+
batch_plan = estimate_batch_plan(
|
| 741 |
+
selected,
|
| 742 |
+
tuple(args.communities),
|
| 743 |
+
args.batch_size,
|
| 744 |
+
args.max_batch_bytes,
|
| 745 |
+
)
|
| 746 |
+
logger.info(
|
| 747 |
+
"commit_plan estimated_commits=%s by_community=%s note=one_successful_batch_equals_one_commit",
|
| 748 |
+
sum(item["batches"] for item in batch_plan.values()),
|
| 749 |
+
batch_plan,
|
| 750 |
+
)
|
| 751 |
+
logger.info(
|
| 752 |
+
"storage_policy source_images_unchanged=1 local_image_copies=0 local_archives=0"
|
| 753 |
+
)
|
| 754 |
+
if args.plan_only:
|
| 755 |
+
return 0
|
| 756 |
+
state_path = args.cache_root / "upload_state.jsonl"
|
| 757 |
+
completed = failed = rate_limits = 0
|
| 758 |
+
completed_bytes = 0
|
| 759 |
+
started = time.time()
|
| 760 |
+
batches = (
|
| 761 |
+
test_batched(selected, args.max_batch_bytes)
|
| 762 |
+
if args.test
|
| 763 |
+
else community_batched(
|
| 764 |
+
selected,
|
| 765 |
+
tuple(args.communities),
|
| 766 |
+
args.batch_size,
|
| 767 |
+
args.max_batch_bytes,
|
| 768 |
+
)
|
| 769 |
+
)
|
| 770 |
+
uploaded_before = 0
|
| 771 |
+
for batch_number, (community, batch) in enumerate(batches, 1):
|
| 772 |
+
if not storage_is_safe(args, logger):
|
| 773 |
+
logger.warning(
|
| 774 |
+
"upload_storage_pressure reason=cleanup_before_continue community=%s batch=%s success=%s failed=%s remaining=%s",
|
| 775 |
+
community, batch_number, completed, failed,
|
| 776 |
+
len(selected) - completed - failed,
|
| 777 |
+
)
|
| 778 |
+
cleanup_rebuildable_batch_cache(args, logger)
|
| 779 |
+
if not storage_is_safe(args, logger):
|
| 780 |
+
wait_for_storage_recovery(args, logger, "soft_storage_floor")
|
| 781 |
+
if storage_at_hard_floor(args, logger):
|
| 782 |
+
logger.error(
|
| 783 |
+
"upload_stopped reason=hard_storage_floor community=%s batch=%s success=%s failed=%s remaining=%s",
|
| 784 |
+
community, batch_number, completed, failed,
|
| 785 |
+
len(selected) - completed - failed,
|
| 786 |
+
)
|
| 787 |
+
return 75
|
| 788 |
+
logger.info(
|
| 789 |
+
"directory_batch_plan batch=%s community=%s files=%s bytes=%s",
|
| 790 |
+
batch_number,
|
| 791 |
+
community,
|
| 792 |
+
len(batch),
|
| 793 |
+
sum(item["size"] for item in batch),
|
| 794 |
+
)
|
| 795 |
+
ok, bad, _, commit_sha, batch_rate_limits = upload_batch(api, args, logger, batch, batch_number, state_path)
|
| 796 |
+
completed += ok
|
| 797 |
+
failed += bad
|
| 798 |
+
rate_limits += batch_rate_limits
|
| 799 |
+
if ok:
|
| 800 |
+
completed_bytes += sum(item["size"] for item in batch if Path(item["local_path"]).exists())
|
| 801 |
+
uploaded_before += ok
|
| 802 |
+
elapsed = max(time.time() - started, 0.001)
|
| 803 |
+
byte_speed = completed_bytes / elapsed
|
| 804 |
+
remaining_bytes = max(total_bytes - completed_bytes, 0)
|
| 805 |
+
eta_seconds = remaining_bytes / byte_speed if byte_speed > 0 else None
|
| 806 |
+
logger.info(
|
| 807 |
+
"upload_progress batches=%s community=%s success=%s failed=%s skipped=%s uploaded_bytes=%s remaining=%s avg_speed=%.2f_files_per_sec avg_mib_per_sec=%.2f eta_seconds=%s commit=%s",
|
| 808 |
+
batch_number,
|
| 809 |
+
community,
|
| 810 |
+
completed,
|
| 811 |
+
failed,
|
| 812 |
+
skipped,
|
| 813 |
+
completed_bytes,
|
| 814 |
+
len(selected) - completed - failed,
|
| 815 |
+
completed / elapsed,
|
| 816 |
+
byte_speed / (1024**2),
|
| 817 |
+
round(eta_seconds) if eta_seconds is not None else None,
|
| 818 |
+
commit_sha,
|
| 819 |
+
)
|
| 820 |
+
if args.test:
|
| 821 |
+
after = remote_file_sizes(api, args, logger)
|
| 822 |
+
mismatches = [
|
| 823 |
+
record["upload_path"]
|
| 824 |
+
for record in selected
|
| 825 |
+
if after.get(record["upload_path"]) != record["size"]
|
| 826 |
+
]
|
| 827 |
+
cache_images = [
|
| 828 |
+
str(path)
|
| 829 |
+
for path in args.cache_root.rglob("*")
|
| 830 |
+
if path.is_file() and path.suffix.lower() in {".jpg", ".jpeg", ".png", ".webp", ".gif", ".bmp", ".tif", ".tiff", ".avif"}
|
| 831 |
+
]
|
| 832 |
+
state_after = load_latest_state(args)
|
| 833 |
+
state_missing = [
|
| 834 |
+
record["upload_path"]
|
| 835 |
+
for record in selected
|
| 836 |
+
if state_after.get(record["upload_path"], {}).get("status") != "uploaded"
|
| 837 |
+
]
|
| 838 |
+
if mismatches or cache_images or state_missing or rate_limits:
|
| 839 |
+
logger.error(
|
| 840 |
+
"test_verification_failed mismatches=%s cache_image_copies=%s state_missing=%s rate_limits=%s",
|
| 841 |
+
mismatches,
|
| 842 |
+
cache_images,
|
| 843 |
+
state_missing,
|
| 844 |
+
rate_limits,
|
| 845 |
+
)
|
| 846 |
+
return 2
|
| 847 |
+
logger.info(
|
| 848 |
+
"test_verification_complete files=%s remote_paths_and_sizes_ok=1 permissions_ok=1 local_image_copies=0 state_ok=1 rate_limits=0",
|
| 849 |
+
len(selected),
|
| 850 |
+
)
|
| 851 |
+
logger.info("upload_complete revision=%s selected=%s success=%s failed=%s skipped=%s rate_limits=%s", args.revision, len(selected), completed, failed, skipped, rate_limits)
|
| 852 |
+
return 1 if failed else 0
|
| 853 |
+
|
| 854 |
+
|
| 855 |
+
def write_remote_manifest(args, logger: logging.Logger) -> int:
|
| 856 |
+
records = load_inventory(args, logger)
|
| 857 |
+
state = load_latest_state(args)
|
| 858 |
+
api = HfApi()
|
| 859 |
+
remote_sizes = remote_file_sizes(api, args, logger)
|
| 860 |
+
manifest_path = args.cache_root / "manifest_remote.jsonl"
|
| 861 |
+
temp_path = manifest_path.with_suffix(".jsonl.part")
|
| 862 |
+
counts = Counter()
|
| 863 |
+
with temp_path.open("w", encoding="utf-8") as handle:
|
| 864 |
+
for record in records:
|
| 865 |
+
remote_path = manifest_remote_path(record, remote_sizes)
|
| 866 |
+
state_record = state.get(remote_path) or state.get(record["relative_path"]) or state.get(record["legacy_relative_path"]) or {}
|
| 867 |
+
exists = remote_sizes.get(remote_path) == record["size"]
|
| 868 |
+
digest = state_record.get("sha256") or sha256_file(Path(record["local_path"]))
|
| 869 |
+
output = {
|
| 870 |
+
"community": record["community"],
|
| 871 |
+
"filename": record["filename"],
|
| 872 |
+
"remote_path": remote_path,
|
| 873 |
+
"size": record["size"],
|
| 874 |
+
"sha256": digest,
|
| 875 |
+
"remote_exists": exists,
|
| 876 |
+
"status": "uploaded" if exists else state_record.get("status", "pending"),
|
| 877 |
+
"error": state_record.get("error"),
|
| 878 |
+
}
|
| 879 |
+
counts[output["status"]] += 1
|
| 880 |
+
handle.write(json.dumps(output, ensure_ascii=False, separators=(",", ":")) + "\n")
|
| 881 |
+
temp_path.replace(manifest_path)
|
| 882 |
+
summary = {"created_at": time.time(), "records": len(records), "counts": dict(counts)}
|
| 883 |
+
(args.cache_root / "manifest_remote_summary.json").write_text(json.dumps(summary, ensure_ascii=False, indent=2), encoding="utf-8")
|
| 884 |
+
manifest_operations = []
|
| 885 |
+
for community in args.communities:
|
| 886 |
+
community_manifest = args.cache_root / f"image_manifest_remote_{community}.jsonl"
|
| 887 |
+
with community_manifest.open("w", encoding="utf-8") as handle:
|
| 888 |
+
for record in records:
|
| 889 |
+
if record["community"] != community:
|
| 890 |
+
continue
|
| 891 |
+
remote_path = manifest_remote_path(record, remote_sizes)
|
| 892 |
+
state_record = state.get(remote_path) or state.get(record["relative_path"]) or state.get(record["legacy_relative_path"]) or {}
|
| 893 |
+
exists = remote_sizes.get(remote_path) == record["size"]
|
| 894 |
+
digest = state_record.get("sha256") or sha256_file(Path(record["local_path"]))
|
| 895 |
+
output = {
|
| 896 |
+
"community": record["community"],
|
| 897 |
+
"filename": record["filename"],
|
| 898 |
+
"remote_path": remote_path,
|
| 899 |
+
"size": record["size"],
|
| 900 |
+
"sha256": digest,
|
| 901 |
+
"remote_exists": exists,
|
| 902 |
+
"status": "uploaded" if exists else state_record.get("status", "pending"),
|
| 903 |
+
"error": state_record.get("error"),
|
| 904 |
+
}
|
| 905 |
+
handle.write(json.dumps(output, ensure_ascii=False, separators=(",", ":")) + "\n")
|
| 906 |
+
manifest_operations.append(
|
| 907 |
+
CommitOperationAdd(
|
| 908 |
+
path_in_repo=f"reddit/image_manifests/{community}/image_manifest_remote.jsonl",
|
| 909 |
+
path_or_fileobj=community_manifest,
|
| 910 |
+
)
|
| 911 |
+
)
|
| 912 |
+
missing = counts.get("pending", 0) + counts.get("failed", 0)
|
| 913 |
+
inventory_paths = {
|
| 914 |
+
path
|
| 915 |
+
for record in records
|
| 916 |
+
for path in (record["relative_path"], record["legacy_relative_path"])
|
| 917 |
+
}
|
| 918 |
+
remote_extra = sorted(set(remote_sizes) - inventory_paths)
|
| 919 |
+
if missing or remote_extra:
|
| 920 |
+
logger.error(
|
| 921 |
+
"manifest_remote_upload_refused missing_or_mismatched=%s remote_extra=%s",
|
| 922 |
+
missing,
|
| 923 |
+
len(remote_extra),
|
| 924 |
+
)
|
| 925 |
+
return 2
|
| 926 |
+
try:
|
| 927 |
+
info = api.create_commit(
|
| 928 |
+
repo_id=args.repo_id,
|
| 929 |
+
operations=manifest_operations,
|
| 930 |
+
commit_message="Update Reddit remote image manifests",
|
| 931 |
+
repo_type="dataset",
|
| 932 |
+
revision=args.revision,
|
| 933 |
+
num_threads=args.upload_threads,
|
| 934 |
+
)
|
| 935 |
+
logger.info("manifest_remote_uploaded commit=%s files=%s", getattr(info, "oid", None), len(manifest_operations))
|
| 936 |
+
except Exception:
|
| 937 |
+
logger.exception("manifest_remote_upload_failed")
|
| 938 |
+
raise
|
| 939 |
+
logger.info("manifest_cache_complete records=%s counts=%s path=%s", len(records), dict(counts), manifest_path)
|
| 940 |
+
return 0
|
| 941 |
+
|
| 942 |
+
|
| 943 |
+
def main() -> int:
|
| 944 |
+
parser = argparse.ArgumentParser()
|
| 945 |
+
parser.add_argument("command", choices=("inventory", "upload", "manifest"))
|
| 946 |
+
parser.add_argument("--repo-id", default=DEFAULT_REPO_ID)
|
| 947 |
+
parser.add_argument("--revision", default=DEFAULT_REVISION)
|
| 948 |
+
parser.add_argument("--source-root", type=Path, default=DEFAULT_SOURCE_ROOT)
|
| 949 |
+
parser.add_argument("--overflow-root", type=Path, default=DEFAULT_OVERFLOW_ROOT)
|
| 950 |
+
parser.add_argument("--cache-root", type=Path, default=DEFAULT_CACHE_ROOT)
|
| 951 |
+
parser.add_argument("--communities", nargs="+", choices=COMMUNITIES, default=list(COMMUNITIES))
|
| 952 |
+
parser.add_argument(
|
| 953 |
+
"--batch-size",
|
| 954 |
+
type=int,
|
| 955 |
+
default=10000,
|
| 956 |
+
help="Maximum files per community directory batch; files are also capped by --max-batch-bytes. Lower values reduce per-commit failure risk.",
|
| 957 |
+
)
|
| 958 |
+
parser.add_argument("--max-batch-bytes", type=int, default=5 * 1024 * 1024 * 1024)
|
| 959 |
+
parser.add_argument(
|
| 960 |
+
"--upload-threads",
|
| 961 |
+
type=int,
|
| 962 |
+
default=6,
|
| 963 |
+
help="Concurrent file uploads inside each large commit; default is 6.",
|
| 964 |
+
)
|
| 965 |
+
parser.add_argument("--request-timeout", type=float, default=180.0)
|
| 966 |
+
parser.add_argument("--batch-retries", type=int, default=3)
|
| 967 |
+
parser.add_argument("--retry-backoff-seconds", type=float, default=10.0)
|
| 968 |
+
parser.add_argument("--rate-limit-backoff-seconds", type=float, default=3700.0)
|
| 969 |
+
parser.add_argument("--rate-limit-poll-seconds", type=float, default=300.0)
|
| 970 |
+
parser.add_argument("--heartbeat-seconds", type=float, default=30.0)
|
| 971 |
+
parser.add_argument("--min-c-free-gib", type=float, default=5.0,
|
| 972 |
+
help="Soft watermark: clean rebuildable cache when below this value.")
|
| 973 |
+
parser.add_argument("--min-d-free-gib", type=float, default=2.0)
|
| 974 |
+
parser.add_argument("--hard-c-floor-gib", type=float, default=1.0,
|
| 975 |
+
help="Hard C: floor; exit only below this value.")
|
| 976 |
+
parser.add_argument("--hard-d-floor-gib", type=float, default=2.0,
|
| 977 |
+
help="Hard D: floor; exit only below this value.")
|
| 978 |
+
parser.add_argument(
|
| 979 |
+
"--storage-recovery-buffer-gib", type=float, default=1.0,
|
| 980 |
+
help="Extra free space required before resuming after a threshold pause.",
|
| 981 |
+
)
|
| 982 |
+
parser.add_argument(
|
| 983 |
+
"--storage-check-seconds", type=float, default=60.0,
|
| 984 |
+
help="How often a paused uploader checks disk space.",
|
| 985 |
+
)
|
| 986 |
+
parser.add_argument("--test", action="store_true")
|
| 987 |
+
parser.add_argument("--test-per-community", type=int, default=3)
|
| 988 |
+
parser.add_argument("--limit", type=int)
|
| 989 |
+
parser.add_argument("--plan-only", action="store_true")
|
| 990 |
+
parser.add_argument("--rebuild-inventory", action="store_true")
|
| 991 |
+
args = parser.parse_args()
|
| 992 |
+
if min(args.batch_size, args.max_batch_bytes, args.request_timeout, args.batch_retries, args.heartbeat_seconds, args.rate_limit_poll_seconds, args.min_c_free_gib, args.min_d_free_gib, args.hard_c_floor_gib, args.hard_d_floor_gib, args.storage_recovery_buffer_gib, args.storage_check_seconds) <= 0:
|
| 993 |
+
parser.error("batch, timeout, retry, and heartbeat values must be positive")
|
| 994 |
+
if args.hard_c_floor_gib >= args.min_c_free_gib or args.hard_d_floor_gib > args.min_d_free_gib:
|
| 995 |
+
parser.error("hard storage floors must be below C soft watermark and no higher than D soft watermark")
|
| 996 |
+
configure_http_client(args.request_timeout)
|
| 997 |
+
logger = setup_logging(args.cache_root)
|
| 998 |
+
logger.info("command_start command=%s pid=%s", args.command, os.getpid())
|
| 999 |
+
if args.command == "inventory":
|
| 1000 |
+
build_inventory(args, logger)
|
| 1001 |
+
return 0
|
| 1002 |
+
if args.command == "manifest":
|
| 1003 |
+
return write_remote_manifest(args, logger)
|
| 1004 |
+
release_upload_lock = acquire_upload_lock(args.cache_root, logger)
|
| 1005 |
+
try:
|
| 1006 |
+
return upload(args, logger)
|
| 1007 |
+
finally:
|
| 1008 |
+
release_upload_lock()
|
| 1009 |
+
|
| 1010 |
+
|
| 1011 |
+
if __name__ == "__main__":
|
| 1012 |
+
raise SystemExit(main())
|
reddit/_rescue_20260917/raw/scripts/upload_reddit_images_large_folder.py
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Resume Reddit image upload with Hugging Face's resilient large-folder uploader.
|
| 2 |
+
|
| 3 |
+
The staging tree contains symbolic links only. Image bytes remain in the source
|
| 4 |
+
directories on D:, while the local tree supplies the desired remote layout.
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
from __future__ import annotations
|
| 8 |
+
|
| 9 |
+
import argparse
|
| 10 |
+
import json
|
| 11 |
+
import logging
|
| 12 |
+
import os
|
| 13 |
+
import shutil
|
| 14 |
+
import sys
|
| 15 |
+
from pathlib import Path
|
| 16 |
+
|
| 17 |
+
from huggingface_hub import HfApi
|
| 18 |
+
|
| 19 |
+
DEFAULT_REPO_ID = "Geo-Club/Geo-Video"
|
| 20 |
+
DEFAULT_REVISION = "reddit"
|
| 21 |
+
DEFAULT_SOURCE_ROOT = Path(r"D:\GeoAgent\Geo-CoT dataset\外网图像地理定位数据收集\reddit_posts\solved_communities")
|
| 22 |
+
DEFAULT_OVERFLOW_ROOT = Path(r"C:\GeoAgent_reddit_overflow\solved_communities")
|
| 23 |
+
DEFAULT_CACHE_ROOT = Path(r"C:\GeoAgent_hf_upload_cache\reddit")
|
| 24 |
+
DEFAULT_VIEW_ROOT = Path(r"C:\GeoAgent_hf_upload_large_folder\reddit")
|
| 25 |
+
COMMUNITIES = ("whereisthis", "GeoPuzzle", "PictureGame")
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
def read_jsonl(path: Path):
|
| 29 |
+
if not path.exists():
|
| 30 |
+
return
|
| 31 |
+
with path.open("r", encoding="utf-8") as handle:
|
| 32 |
+
for line in handle:
|
| 33 |
+
if line.strip():
|
| 34 |
+
yield json.loads(line)
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
def remote_sizes(api: HfApi, args, logger: logging.Logger) -> dict[str, int]:
|
| 38 |
+
entries = api.list_repo_tree(
|
| 39 |
+
args.repo_id,
|
| 40 |
+
path_in_repo="reddit/images",
|
| 41 |
+
recursive=True,
|
| 42 |
+
revision=args.revision,
|
| 43 |
+
repo_type="dataset",
|
| 44 |
+
)
|
| 45 |
+
result = {
|
| 46 |
+
entry.path: int(entry.size)
|
| 47 |
+
for entry in entries
|
| 48 |
+
if getattr(entry, "size", None) is not None
|
| 49 |
+
}
|
| 50 |
+
logger.info("remote_inventory_complete files=%s bytes=%s", len(result), sum(result.values()))
|
| 51 |
+
return result
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
def setup_logging(path: Path) -> logging.Logger:
|
| 55 |
+
path.parent.mkdir(parents=True, exist_ok=True)
|
| 56 |
+
logger = logging.getLogger("reddit_large_folder")
|
| 57 |
+
logger.setLevel(logging.INFO)
|
| 58 |
+
logger.handlers.clear()
|
| 59 |
+
handler = logging.FileHandler(path, encoding="utf-8")
|
| 60 |
+
handler.setFormatter(logging.Formatter("%(asctime)s %(levelname)s %(message)s"))
|
| 61 |
+
console = logging.StreamHandler(sys.stdout)
|
| 62 |
+
console.setFormatter(handler.formatter)
|
| 63 |
+
logger.addHandler(handler)
|
| 64 |
+
logger.addHandler(console)
|
| 65 |
+
return logger
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
def storage_ok(args, logger: logging.Logger) -> bool:
|
| 69 |
+
c_free = shutil.disk_usage(args.view_root.anchor or "C:\\").free / (1024**3)
|
| 70 |
+
d_free = shutil.disk_usage(args.source_root.anchor or "D:\\").free / (1024**3)
|
| 71 |
+
ok = c_free >= args.min_c_free_gib and d_free >= args.min_d_free_gib
|
| 72 |
+
logger.info(
|
| 73 |
+
"storage_check c_free_gib=%.2f d_free_gib=%.2f safe=%s thresholds=%.1f/%.1f",
|
| 74 |
+
c_free, d_free, int(ok), args.min_c_free_gib, args.min_d_free_gib,
|
| 75 |
+
)
|
| 76 |
+
return ok
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
def make_link_view(args, logger: logging.Logger, limit: int | None) -> int:
|
| 80 |
+
inventory = list(read_jsonl(args.cache_root / "inventory.jsonl") or ())
|
| 81 |
+
api = HfApi()
|
| 82 |
+
remote = remote_sizes(api, args, logger)
|
| 83 |
+
pending = [
|
| 84 |
+
record for record in inventory
|
| 85 |
+
if record["community"] in args.communities
|
| 86 |
+
and record["relative_path"] not in remote
|
| 87 |
+
and record["legacy_relative_path"] not in remote
|
| 88 |
+
]
|
| 89 |
+
if limit is not None:
|
| 90 |
+
pending = pending[:limit]
|
| 91 |
+
logger.info("large_folder_view_plan pending=%s limit=%s", len(pending), limit)
|
| 92 |
+
args.view_root.mkdir(parents=True, exist_ok=True)
|
| 93 |
+
created = 0
|
| 94 |
+
for record in pending:
|
| 95 |
+
source = Path(record["local_path"])
|
| 96 |
+
target = args.view_root / record["relative_path"]
|
| 97 |
+
if not source.is_file() or source.stat().st_size != record["size"]:
|
| 98 |
+
logger.error("source_invalid path=%s", source)
|
| 99 |
+
continue
|
| 100 |
+
target.parent.mkdir(parents=True, exist_ok=True)
|
| 101 |
+
if target.exists() or target.is_symlink():
|
| 102 |
+
if target.is_symlink() and target.resolve() == source.resolve():
|
| 103 |
+
continue
|
| 104 |
+
raise RuntimeError(f"Refusing to overwrite existing view entry: {target}")
|
| 105 |
+
target.symlink_to(source, target_is_directory=False)
|
| 106 |
+
created += 1
|
| 107 |
+
if created % 1000 == 0:
|
| 108 |
+
logger.info("large_folder_view_progress links=%s", created)
|
| 109 |
+
logger.info("large_folder_view_complete links=%s bytes=%s copies=0", created, sum(r["size"] for r in pending))
|
| 110 |
+
return created
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
def main() -> int:
|
| 114 |
+
parser = argparse.ArgumentParser()
|
| 115 |
+
parser.add_argument("command", choices=("prepare", "upload"))
|
| 116 |
+
parser.add_argument("--repo-id", default=DEFAULT_REPO_ID)
|
| 117 |
+
parser.add_argument("--revision", default=DEFAULT_REVISION)
|
| 118 |
+
parser.add_argument("--source-root", type=Path, default=DEFAULT_SOURCE_ROOT)
|
| 119 |
+
parser.add_argument("--cache-root", type=Path, default=DEFAULT_CACHE_ROOT)
|
| 120 |
+
parser.add_argument("--view-root", type=Path, default=DEFAULT_VIEW_ROOT)
|
| 121 |
+
parser.add_argument("--communities", nargs="+", choices=COMMUNITIES, default=list(COMMUNITIES))
|
| 122 |
+
parser.add_argument("--workers", type=int, default=8)
|
| 123 |
+
parser.add_argument("--limit", type=int)
|
| 124 |
+
parser.add_argument("--print-report-every", type=int, default=60)
|
| 125 |
+
parser.add_argument("--min-c-free-gib", type=float, default=5.0)
|
| 126 |
+
parser.add_argument("--min-d-free-gib", type=float, default=2.0)
|
| 127 |
+
args = parser.parse_args()
|
| 128 |
+
if args.command == "upload":
|
| 129 |
+
args.cache_root.mkdir(parents=True, exist_ok=True)
|
| 130 |
+
sys.stdout = (args.cache_root / "large_folder_console.log").open(
|
| 131 |
+
"a", encoding="utf-8", buffering=1
|
| 132 |
+
)
|
| 133 |
+
sys.stderr = (args.cache_root / "large_folder_console_error.log").open(
|
| 134 |
+
"a", encoding="utf-8", buffering=1
|
| 135 |
+
)
|
| 136 |
+
logger = setup_logging(args.cache_root / "large_folder_upload.log")
|
| 137 |
+
logger.info("command_start command=%s pid=%s", args.command, os.getpid())
|
| 138 |
+
if not storage_ok(args, logger):
|
| 139 |
+
logger.error("upload_paused reason=storage_threshold")
|
| 140 |
+
return 75
|
| 141 |
+
if args.command == "prepare":
|
| 142 |
+
make_link_view(args, logger, args.limit)
|
| 143 |
+
return 0
|
| 144 |
+
if not args.view_root.exists():
|
| 145 |
+
raise RuntimeError("View directory is missing; run prepare first")
|
| 146 |
+
if args.limit is not None:
|
| 147 |
+
raise ValueError("--limit is only supported by prepare")
|
| 148 |
+
logger.info("large_folder_upload_start view_root=%s workers=%s copies=0", args.view_root, args.workers)
|
| 149 |
+
HfApi().upload_large_folder(
|
| 150 |
+
repo_id=args.repo_id,
|
| 151 |
+
folder_path=args.view_root,
|
| 152 |
+
repo_type="dataset",
|
| 153 |
+
revision=args.revision,
|
| 154 |
+
num_workers=args.workers,
|
| 155 |
+
print_report=True,
|
| 156 |
+
print_report_every=args.print_report_every,
|
| 157 |
+
)
|
| 158 |
+
logger.info("large_folder_upload_complete revision=%s", args.revision)
|
| 159 |
+
return 0
|
| 160 |
+
|
| 161 |
+
|
| 162 |
+
if __name__ == "__main__":
|
| 163 |
+
raise SystemExit(main())
|
reddit/_rescue_20260917/raw/scripts/validate_canonical_reddit_metadata.py
ADDED
|
@@ -0,0 +1,233 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Create and validate the final canonical Reddit image manifest.
|
| 2 |
+
|
| 3 |
+
This is a local, non-destructive gate. It neither uploads nor deletes files.
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
from __future__ import annotations
|
| 7 |
+
|
| 8 |
+
import argparse
|
| 9 |
+
import json
|
| 10 |
+
import re
|
| 11 |
+
import time
|
| 12 |
+
from collections import Counter, defaultdict
|
| 13 |
+
from pathlib import Path
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
IMAGE_RE = re.compile(
|
| 17 |
+
rb"reddit/images/(?:whereisthis|GeoPuzzle|PictureGame)/(?:canonical/)?(?:[0-9]{4}/)?"
|
| 18 |
+
rb"[A-Za-z0-9._-]+\.(?:jpeg|jpg|png|webp|gif|bmp|tiff|tif|avif)(?![A-Za-z0-9.])",
|
| 19 |
+
re.IGNORECASE,
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def jsonl(path: Path):
|
| 24 |
+
with path.open("r", encoding="utf-8") as handle:
|
| 25 |
+
for number, line in enumerate(handle, 1):
|
| 26 |
+
if line.strip():
|
| 27 |
+
try:
|
| 28 |
+
yield json.loads(line)
|
| 29 |
+
except json.JSONDecodeError as exc:
|
| 30 |
+
raise ValueError(f"invalid JSON: {path}:{number}") from exc
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
def main() -> int:
|
| 34 |
+
parser = argparse.ArgumentParser()
|
| 35 |
+
parser.add_argument("--inventory", type=Path, required=True)
|
| 36 |
+
parser.add_argument("--naming-root", type=Path, required=True)
|
| 37 |
+
parser.add_argument("--dedup-root", type=Path, required=True)
|
| 38 |
+
parser.add_argument("--association-root", type=Path, required=True)
|
| 39 |
+
parser.add_argument("--bundle-root", type=Path, required=True)
|
| 40 |
+
args = parser.parse_args()
|
| 41 |
+
started = time.time()
|
| 42 |
+
reddit_root = args.bundle_root / "reddit"
|
| 43 |
+
manifest_root = reddit_root / "image_manifests"
|
| 44 |
+
report_root = reddit_root / "reports"
|
| 45 |
+
manifest_root.mkdir(parents=True, exist_ok=True)
|
| 46 |
+
report_root.mkdir(parents=True, exist_ok=True)
|
| 47 |
+
|
| 48 |
+
inventory = {(x["community"], x["filename"]): x for x in jsonl(args.inventory)}
|
| 49 |
+
associations = {(x["community"], x["filename"]): x for x in jsonl(args.association_root / "association_recovery.jsonl")}
|
| 50 |
+
naming = {}
|
| 51 |
+
old_path_to_key = {}
|
| 52 |
+
for x in jsonl(args.naming_root / "canonical_image_mapping.jsonl"):
|
| 53 |
+
key = (x["community"], x["old_filename"])
|
| 54 |
+
naming[key] = x
|
| 55 |
+
old_path_to_key[x["old_remote_path"]] = key
|
| 56 |
+
|
| 57 |
+
dedup = {x["original_path"]: x["canonical_path"] for x in jsonl(args.dedup_root / "content_dedup_mapping.jsonl")}
|
| 58 |
+
placeholder_groups = json.loads((args.dedup_root / "placeholder_candidates.json").read_text(encoding="utf-8"))
|
| 59 |
+
placeholder_hashes = {
|
| 60 |
+
x["sha256"] for x in placeholder_groups
|
| 61 |
+
if x.get("count") in {59, 3229} or all(int(m.get("size", 0)) in {114, 503} for m in x.get("members", []))
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
errors = []
|
| 65 |
+
rows = []
|
| 66 |
+
deletion_candidates = []
|
| 67 |
+
placeholder_deletion_candidates = []
|
| 68 |
+
sha_targets = defaultdict(set)
|
| 69 |
+
community_stats = defaultdict(Counter)
|
| 70 |
+
target_paths = set()
|
| 71 |
+
placeholder_files = 0
|
| 72 |
+
for key, inv in sorted(inventory.items()):
|
| 73 |
+
name = naming.get(key)
|
| 74 |
+
assoc = associations.get(key)
|
| 75 |
+
if not name:
|
| 76 |
+
errors.append({"type": "missing_naming", "key": key})
|
| 77 |
+
continue
|
| 78 |
+
if not assoc or not assoc.get("references"):
|
| 79 |
+
errors.append({"type": "missing_association", "key": key})
|
| 80 |
+
old_path = name["old_remote_path"]
|
| 81 |
+
sha = name["sha256"]
|
| 82 |
+
is_placeholder = sha in placeholder_hashes
|
| 83 |
+
canonical_old = None if is_placeholder else dedup.get(old_path, old_path)
|
| 84 |
+
canonical_key = old_path_to_key.get(canonical_old) if canonical_old else None
|
| 85 |
+
canonical_name = naming.get(canonical_key) if canonical_key else None
|
| 86 |
+
if not is_placeholder and not canonical_name:
|
| 87 |
+
errors.append({"type": "missing_canonical_target", "old_path": old_path, "canonical_old": canonical_old})
|
| 88 |
+
continue
|
| 89 |
+
target = None if is_placeholder else canonical_name["new_remote_path"]
|
| 90 |
+
status = "invalid_placeholder_image" if is_placeholder else "valid"
|
| 91 |
+
is_canonical = False if is_placeholder else old_path == canonical_old
|
| 92 |
+
local = Path(name["local_path"])
|
| 93 |
+
source_ok = local.is_file() and local.stat().st_size == int(name["size"])
|
| 94 |
+
if not source_ok:
|
| 95 |
+
errors.append({"type": "source_missing_or_size_changed", "old_path": old_path, "local_path": str(local)})
|
| 96 |
+
row = {
|
| 97 |
+
"community": key[0],
|
| 98 |
+
"filename": key[1],
|
| 99 |
+
"original_path": old_path,
|
| 100 |
+
"canonical_path": target,
|
| 101 |
+
"size": int(name["size"]),
|
| 102 |
+
"sha256": sha,
|
| 103 |
+
"post_ids": (assoc or {}).get("post_ids", []),
|
| 104 |
+
"references": (assoc or {}).get("references", []),
|
| 105 |
+
"association_count": (assoc or {}).get("association_count", 0),
|
| 106 |
+
"status": status,
|
| 107 |
+
"is_canonical": is_canonical,
|
| 108 |
+
"source_exists_and_size_matches": source_ok,
|
| 109 |
+
"remote_exists": False,
|
| 110 |
+
"delete_allowed": False,
|
| 111 |
+
}
|
| 112 |
+
rows.append(row)
|
| 113 |
+
if target:
|
| 114 |
+
target_paths.add(target)
|
| 115 |
+
sha_targets[sha].add(target)
|
| 116 |
+
community_stats[key[0]]["files"] += 1
|
| 117 |
+
community_stats[key[0]]["bytes"] += int(name["size"])
|
| 118 |
+
community_stats[key[0]][status] += 1
|
| 119 |
+
if is_placeholder:
|
| 120 |
+
placeholder_files += 1
|
| 121 |
+
placeholder_deletion_candidates.append({
|
| 122 |
+
"original_path": old_path,
|
| 123 |
+
"canonical_path": None,
|
| 124 |
+
"sha256": sha,
|
| 125 |
+
"reason": "invalid_placeholder_image",
|
| 126 |
+
"delete_allowed": False,
|
| 127 |
+
"blocked_by": "text_reference_commit_and_remote_verification_pending",
|
| 128 |
+
})
|
| 129 |
+
elif not is_canonical:
|
| 130 |
+
deletion_candidates.append({
|
| 131 |
+
"original_path": old_path,
|
| 132 |
+
"canonical_path": target,
|
| 133 |
+
"sha256": sha,
|
| 134 |
+
"reason": "valid_duplicate_content",
|
| 135 |
+
"delete_allowed": False,
|
| 136 |
+
"blocked_by": "canonical_remote_upload_and_reference_verification_pending",
|
| 137 |
+
})
|
| 138 |
+
|
| 139 |
+
invalid_sha_target_counts = []
|
| 140 |
+
for sha, targets in sha_targets.items():
|
| 141 |
+
expected = placeholder_files and sha in placeholder_hashes
|
| 142 |
+
if not expected and len(targets) != 1:
|
| 143 |
+
invalid_sha_target_counts.append({"sha256": sha, "target_count": len(targets)})
|
| 144 |
+
if invalid_sha_target_counts:
|
| 145 |
+
errors.extend({"type": "valid_sha_has_multiple_targets", **x} for x in invalid_sha_target_counts)
|
| 146 |
+
|
| 147 |
+
manifest_path = manifest_root / "canonical_image_manifest.jsonl"
|
| 148 |
+
with manifest_path.open("w", encoding="utf-8", newline="\n") as handle:
|
| 149 |
+
for row in rows:
|
| 150 |
+
handle.write(json.dumps(row, ensure_ascii=False, separators=(",", ":")) + "\n")
|
| 151 |
+
candidate_path = manifest_root / "remote_deletion_candidates_pending.jsonl"
|
| 152 |
+
with candidate_path.open("w", encoding="utf-8", newline="\n") as handle:
|
| 153 |
+
for row in deletion_candidates:
|
| 154 |
+
handle.write(json.dumps(row, ensure_ascii=False, separators=(",", ":")) + "\n")
|
| 155 |
+
placeholder_candidate_path = manifest_root / "invalid_placeholder_remote_candidates_pending.jsonl"
|
| 156 |
+
with placeholder_candidate_path.open("w", encoding="utf-8", newline="\n") as handle:
|
| 157 |
+
for row in placeholder_deletion_candidates:
|
| 158 |
+
handle.write(json.dumps(row, ensure_ascii=False, separators=(",", ":")) + "\n")
|
| 159 |
+
|
| 160 |
+
reference_count = 0
|
| 161 |
+
unresolved = Counter()
|
| 162 |
+
placeholder_references = 0
|
| 163 |
+
files_scanned = 0
|
| 164 |
+
bytes_scanned = 0
|
| 165 |
+
for root_name in ("posts_tagged", "manual_review", "image_manifests"):
|
| 166 |
+
root = reddit_root / root_name
|
| 167 |
+
for path in sorted(root.rglob("*.jsonl")):
|
| 168 |
+
if path in {manifest_path, candidate_path, placeholder_candidate_path} or path.name == "canonical_path_mapping.jsonl":
|
| 169 |
+
continue
|
| 170 |
+
files_scanned += 1
|
| 171 |
+
with path.open("rb") as handle:
|
| 172 |
+
for line in handle:
|
| 173 |
+
bytes_scanned += len(line)
|
| 174 |
+
for raw in IMAGE_RE.findall(line):
|
| 175 |
+
value = raw.decode("utf-8", errors="replace")
|
| 176 |
+
reference_count += 1
|
| 177 |
+
if value not in target_paths:
|
| 178 |
+
unresolved[value] += 1
|
| 179 |
+
if unresolved:
|
| 180 |
+
errors.append({"type": "unresolved_output_references", "paths": len(unresolved), "occurrences": sum(unresolved.values())})
|
| 181 |
+
|
| 182 |
+
for row in rows:
|
| 183 |
+
if row["status"] == "invalid_placeholder_image":
|
| 184 |
+
placeholder_references += row["association_count"]
|
| 185 |
+
|
| 186 |
+
checks = {
|
| 187 |
+
"inventory_equals_manifest": len(inventory) == len(rows) == 225307,
|
| 188 |
+
"all_images_associated": len(associations) == len(inventory) and all(x["association_count"] > 0 for x in rows),
|
| 189 |
+
"all_sources_exist_and_size_match": all(x["source_exists_and_size_matches"] for x in rows),
|
| 190 |
+
"valid_sha_single_target": not invalid_sha_target_counts,
|
| 191 |
+
"placeholder_hash_count_is_two": len(placeholder_hashes) == 2,
|
| 192 |
+
"placeholder_files_excluded_from_targets": all(
|
| 193 |
+
r["canonical_path"] is None and not r["is_canonical"]
|
| 194 |
+
for r in rows if r["sha256"] in placeholder_hashes
|
| 195 |
+
),
|
| 196 |
+
"placeholder_references_removed": all(
|
| 197 |
+
path not in unresolved for path in (r["original_path"] for r in rows if r["sha256"] in placeholder_hashes)
|
| 198 |
+
),
|
| 199 |
+
"all_output_references_resolve_locally": not unresolved,
|
| 200 |
+
"remote_unchanged": True,
|
| 201 |
+
"deletion_is_blocked_until_remote_verification": True,
|
| 202 |
+
}
|
| 203 |
+
report = {
|
| 204 |
+
"status": "passed_local_gate_remote_pending" if all(checks.values()) else "failed_local_gate",
|
| 205 |
+
"created_at": time.time(),
|
| 206 |
+
"elapsed_seconds": round(time.time() - started, 2),
|
| 207 |
+
"checks": checks,
|
| 208 |
+
"inventory_records": len(inventory),
|
| 209 |
+
"manifest_records": len(rows),
|
| 210 |
+
"unique_canonical_targets": len(target_paths),
|
| 211 |
+
"valid_duplicate_deletion_candidates": len(deletion_candidates),
|
| 212 |
+
"placeholder_files": placeholder_files,
|
| 213 |
+
"placeholder_remote_deletion_candidates": len(placeholder_deletion_candidates),
|
| 214 |
+
"placeholder_reference_associations": placeholder_references,
|
| 215 |
+
"output_reference_occurrences": reference_count,
|
| 216 |
+
"unresolved_output_paths": len(unresolved),
|
| 217 |
+
"files_scanned": files_scanned,
|
| 218 |
+
"bytes_scanned": bytes_scanned,
|
| 219 |
+
"community_stats": {k: dict(v) for k, v in community_stats.items()},
|
| 220 |
+
"error_count": len(errors),
|
| 221 |
+
"remote_modified": False,
|
| 222 |
+
"delete_allowed": False,
|
| 223 |
+
"next_gate": "upload canonical targets to backup/test revision and verify remote size/hash before reference commit or deletion",
|
| 224 |
+
}
|
| 225 |
+
(report_root / "canonical_validation_report.json").write_text(json.dumps(report, ensure_ascii=False, indent=2), encoding="utf-8")
|
| 226 |
+
(report_root / "canonical_validation_errors.json").write_text(json.dumps(errors, ensure_ascii=False, indent=2), encoding="utf-8")
|
| 227 |
+
(report_root / "unresolved_output_references.json").write_text(json.dumps(unresolved, ensure_ascii=False, indent=2), encoding="utf-8")
|
| 228 |
+
print(json.dumps(report, ensure_ascii=False), flush=True)
|
| 229 |
+
return 0 if report["status"] == "passed_local_gate_remote_pending" else 2
|
| 230 |
+
|
| 231 |
+
|
| 232 |
+
if __name__ == "__main__":
|
| 233 |
+
raise SystemExit(main())
|
reddit/_rescue_20260917/raw/solved_whereisthis/download.log
ADDED
|
@@ -0,0 +1,297 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
2026-09-01 18:47:08,601 INFO prepared posts=9873 comments=78032/201544 unique_images=20674
|
| 2 |
+
2026-09-01 18:47:12,209 INFO progress=1/20674 downloaded=1 failed=0 speed=0.04 images/s
|
| 3 |
+
2026-09-01 18:47:16,820 INFO progress=25/20674 downloaded=25 failed=0 speed=0.88 images/s
|
| 4 |
+
2026-09-01 18:47:22,320 INFO progress=50/20674 downloaded=45 failed=5 speed=1.47 images/s
|
| 5 |
+
2026-09-01 18:47:28,164 INFO progress=75/20674 downloaded=67 failed=8 speed=1.88 images/s
|
| 6 |
+
2026-09-01 18:47:32,798 INFO progress=100/20674 downloaded=92 failed=8 speed=2.25 images/s
|
| 7 |
+
2026-09-01 18:47:36,753 INFO progress=125/20674 downloaded=115 failed=10 speed=2.58 images/s
|
| 8 |
+
2026-09-01 18:47:40,104 INFO progress=150/20674 downloaded=139 failed=11 speed=2.90 images/s
|
| 9 |
+
2026-09-01 18:47:43,963 INFO progress=175/20674 downloaded=164 failed=11 speed=3.15 images/s
|
| 10 |
+
2026-09-01 18:47:47,627 INFO progress=200/20674 downloaded=188 failed=12 speed=3.38 images/s
|
| 11 |
+
2026-09-01 18:47:51,105 INFO progress=225/20674 downloaded=212 failed=13 speed=3.59 images/s
|
| 12 |
+
2026-09-01 18:47:54,637 INFO progress=250/20674 downloaded=237 failed=13 speed=3.77 images/s
|
| 13 |
+
2026-09-01 18:47:57,786 INFO progress=275/20674 downloaded=262 failed=13 speed=3.96 images/s
|
| 14 |
+
2026-09-01 18:48:01,238 INFO progress=300/20674 downloaded=287 failed=13 speed=4.12 images/s
|
| 15 |
+
2026-09-01 18:48:05,027 INFO progress=325/20674 downloaded=312 failed=13 speed=4.24 images/s
|
| 16 |
+
2026-09-01 18:48:08,815 INFO progress=350/20674 downloaded=337 failed=13 speed=4.35 images/s
|
| 17 |
+
2026-09-01 18:48:12,538 INFO progress=375/20674 downloaded=361 failed=14 speed=4.46 images/s
|
| 18 |
+
2026-09-01 18:48:16,260 INFO progress=400/20674 downloaded=386 failed=14 speed=4.55 images/s
|
| 19 |
+
2026-09-01 18:48:19,336 INFO progress=425/20674 downloaded=410 failed=15 speed=4.67 images/s
|
| 20 |
+
2026-09-01 18:48:22,961 INFO progress=450/20674 downloaded=435 failed=15 speed=4.76 images/s
|
| 21 |
+
2026-09-01 18:48:26,537 INFO progress=475/20674 downloaded=459 failed=16 speed=4.84 images/s
|
| 22 |
+
2026-09-01 18:48:29,932 INFO progress=500/20674 downloaded=484 failed=16 speed=4.92 images/s
|
| 23 |
+
2026-09-01 18:48:33,319 INFO progress=525/20674 downloaded=509 failed=16 speed=5.00 images/s
|
| 24 |
+
2026-09-01 18:48:36,918 INFO progress=550/20674 downloaded=534 failed=16 speed=5.07 images/s
|
| 25 |
+
2026-09-01 18:48:40,020 INFO progress=575/20674 downloaded=559 failed=16 speed=5.15 images/s
|
| 26 |
+
2026-09-01 18:48:43,689 INFO progress=600/20674 downloaded=582 failed=18 speed=5.20 images/s
|
| 27 |
+
2026-09-01 18:48:47,981 INFO progress=625/20674 downloaded=606 failed=19 speed=5.23 images/s
|
| 28 |
+
2026-09-01 18:48:51,187 INFO progress=650/20674 downloaded=631 failed=19 speed=5.29 images/s
|
| 29 |
+
2026-09-01 18:48:54,741 INFO progress=675/20674 downloaded=656 failed=19 speed=5.34 images/s
|
| 30 |
+
2026-09-01 18:48:58,495 INFO progress=700/20674 downloaded=681 failed=19 speed=5.38 images/s
|
| 31 |
+
2026-09-01 18:49:04,127 INFO progress=725/20674 downloaded=705 failed=20 speed=5.34 images/s
|
| 32 |
+
2026-09-01 18:49:08,619 INFO progress=750/20674 downloaded=727 failed=23 speed=5.35 images/s
|
| 33 |
+
2026-09-01 18:49:13,439 INFO progress=775/20674 downloaded=751 failed=24 speed=5.34 images/s
|
| 34 |
+
2026-09-01 18:49:17,164 INFO progress=800/20674 downloaded=776 failed=24 speed=5.38 images/s
|
| 35 |
+
2026-09-01 18:49:21,030 INFO progress=825/20674 downloaded=801 failed=24 speed=5.40 images/s
|
| 36 |
+
2026-09-01 18:49:24,615 INFO progress=850/20674 downloaded=825 failed=25 speed=5.44 images/s
|
| 37 |
+
2026-09-01 18:49:28,374 INFO progress=875/20674 downloaded=849 failed=26 speed=5.47 images/s
|
| 38 |
+
2026-09-01 18:49:32,044 INFO progress=900/20674 downloaded=873 failed=27 speed=5.50 images/s
|
| 39 |
+
2026-09-01 18:49:35,684 INFO progress=925/20674 downloaded=897 failed=28 speed=5.53 images/s
|
| 40 |
+
2026-09-01 18:49:39,332 INFO progress=950/20674 downloaded=921 failed=29 speed=5.56 images/s
|
| 41 |
+
2026-09-01 18:49:43,570 INFO progress=975/20674 downloaded=946 failed=29 speed=5.57 images/s
|
| 42 |
+
2026-09-01 18:49:46,632 INFO progress=1000/20674 downloaded=969 failed=31 speed=5.61 images/s
|
| 43 |
+
2026-09-01 18:49:50,136 INFO progress=1025/20674 downloaded=994 failed=31 speed=5.64 images/s
|
| 44 |
+
2026-09-01 18:49:53,682 INFO progress=1050/20674 downloaded=1019 failed=31 speed=5.67 images/s
|
| 45 |
+
2026-09-01 18:49:57,542 INFO progress=1075/20674 downloaded=1044 failed=31 speed=5.68 images/s
|
| 46 |
+
2026-09-01 18:50:00,779 INFO progress=1100/20674 downloaded=1068 failed=32 speed=5.72 images/s
|
| 47 |
+
2026-09-01 18:50:04,336 INFO progress=1125/20674 downloaded=1093 failed=32 speed=5.74 images/s
|
| 48 |
+
2026-09-01 18:50:07,169 INFO progress=1150/20674 downloaded=1118 failed=32 speed=5.78 images/s
|
| 49 |
+
2026-09-01 18:50:10,344 INFO progress=1175/20674 downloaded=1143 failed=32 speed=5.82 images/s
|
| 50 |
+
2026-09-01 18:50:13,192 INFO progress=1200/20674 downloaded=1168 failed=32 speed=5.86 images/s
|
| 51 |
+
2026-09-01 19:06:06,763 INFO prepared posts=9873 comments=78032/201544 unique_images=20674
|
| 52 |
+
2026-09-01 19:06:09,073 INFO progress=1/20674 downloaded=1 failed=0 speed=0.05 images/s
|
| 53 |
+
2026-09-01 19:06:10,135 INFO progress=25/20674 downloaded=25 failed=0 speed=1.14 images/s
|
| 54 |
+
2026-09-01 19:06:10,710 INFO progress=50/20674 downloaded=48 failed=2 speed=2.22 images/s
|
| 55 |
+
2026-09-01 19:06:11,193 INFO progress=75/20674 downloaded=71 failed=4 speed=3.26 images/s
|
| 56 |
+
2026-09-01 19:06:11,392 INFO progress=100/20674 downloaded=96 failed=4 speed=4.31 images/s
|
| 57 |
+
2026-09-01 19:06:11,847 INFO progress=125/20674 downloaded=120 failed=5 speed=5.29 images/s
|
| 58 |
+
2026-09-01 19:06:12,219 INFO progress=150/20674 downloaded=145 failed=5 speed=6.25 images/s
|
| 59 |
+
2026-09-01 19:06:12,477 INFO progress=175/20674 downloaded=170 failed=5 speed=7.21 images/s
|
| 60 |
+
2026-09-01 19:06:12,921 INFO progress=200/20674 downloaded=195 failed=5 speed=8.09 images/s
|
| 61 |
+
2026-09-01 19:06:13,944 INFO progress=225/20674 downloaded=219 failed=6 speed=8.74 images/s
|
| 62 |
+
2026-09-01 19:06:14,285 INFO progress=250/20674 downloaded=244 failed=6 speed=9.59 images/s
|
| 63 |
+
2026-09-01 19:06:14,566 INFO progress=275/20674 downloaded=269 failed=6 speed=10.43 images/s
|
| 64 |
+
2026-09-01 19:06:14,973 INFO progress=300/20674 downloaded=293 failed=7 speed=11.21 images/s
|
| 65 |
+
2026-09-01 19:06:15,293 INFO progress=325/20674 downloaded=318 failed=7 speed=12.00 images/s
|
| 66 |
+
2026-09-01 19:06:15,661 INFO progress=350/20674 downloaded=342 failed=8 speed=12.75 images/s
|
| 67 |
+
2026-09-01 19:06:16,129 INFO progress=375/20674 downloaded=365 failed=10 speed=13.43 images/s
|
| 68 |
+
2026-09-01 19:06:16,525 INFO progress=400/20674 downloaded=389 failed=11 speed=14.12 images/s
|
| 69 |
+
2026-09-01 19:06:17,574 INFO progress=425/20674 downloaded=412 failed=13 speed=14.47 images/s
|
| 70 |
+
2026-09-01 19:06:18,681 INFO progress=450/20674 downloaded=436 failed=14 speed=14.76 images/s
|
| 71 |
+
2026-09-01 19:06:19,794 INFO progress=475/20674 downloaded=461 failed=14 speed=15.04 images/s
|
| 72 |
+
2026-09-01 19:06:20,636 INFO progress=500/20674 downloaded=485 failed=15 speed=15.42 images/s
|
| 73 |
+
2026-09-01 19:06:21,564 INFO progress=525/20674 downloaded=510 failed=15 speed=15.74 images/s
|
| 74 |
+
2026-09-01 19:06:22,597 INFO progress=550/20674 downloaded=534 failed=16 speed=15.99 images/s
|
| 75 |
+
2026-09-01 19:06:23,635 INFO progress=575/20674 downloaded=559 failed=16 speed=16.23 images/s
|
| 76 |
+
2026-09-01 19:06:24,640 INFO progress=600/20674 downloaded=583 failed=17 speed=16.47 images/s
|
| 77 |
+
2026-09-01 19:06:25,657 INFO progress=625/20674 downloaded=607 failed=18 speed=16.69 images/s
|
| 78 |
+
2026-09-01 19:06:26,698 INFO progress=650/20674 downloaded=632 failed=18 speed=16.89 images/s
|
| 79 |
+
2026-09-01 19:06:27,731 INFO progress=675/20674 downloaded=657 failed=18 speed=17.08 images/s
|
| 80 |
+
2026-09-01 19:06:28,742 INFO progress=700/20674 downloaded=682 failed=18 speed=17.27 images/s
|
| 81 |
+
2026-09-01 19:06:29,841 INFO progress=725/20674 downloaded=706 failed=19 speed=17.41 images/s
|
| 82 |
+
2026-09-01 19:06:30,303 INFO progress=750/20674 downloaded=731 failed=19 speed=17.81 images/s
|
| 83 |
+
2026-09-01 19:06:30,741 INFO progress=775/20674 downloaded=756 failed=19 speed=18.22 images/s
|
| 84 |
+
2026-09-01 19:06:31,211 INFO progress=800/20674 downloaded=780 failed=20 speed=18.60 images/s
|
| 85 |
+
2026-09-01 19:06:31,653 INFO progress=825/20674 downloaded=805 failed=20 speed=18.99 images/s
|
| 86 |
+
2026-09-01 19:06:32,246 INFO progress=850/20674 downloaded=830 failed=20 speed=19.30 images/s
|
| 87 |
+
2026-09-01 19:06:32,510 INFO progress=875/20674 downloaded=855 failed=20 speed=19.75 images/s
|
| 88 |
+
2026-09-01 19:06:33,043 INFO progress=900/20674 downloaded=879 failed=21 speed=20.07 images/s
|
| 89 |
+
2026-09-01 19:06:33,715 INFO progress=925/20674 downloaded=902 failed=23 speed=20.32 images/s
|
| 90 |
+
2026-09-01 19:06:34,209 INFO progress=950/20674 downloaded=926 failed=24 speed=20.65 images/s
|
| 91 |
+
2026-09-01 19:06:34,501 INFO progress=975/20674 downloaded=950 failed=25 speed=21.06 images/s
|
| 92 |
+
2026-09-01 19:06:35,066 INFO progress=1000/20674 downloaded=974 failed=26 speed=21.34 images/s
|
| 93 |
+
2026-09-01 19:06:35,423 INFO progress=1025/20674 downloaded=998 failed=27 speed=21.71 images/s
|
| 94 |
+
2026-09-01 19:06:36,128 INFO progress=1050/20674 downloaded=1021 failed=29 speed=21.91 images/s
|
| 95 |
+
2026-09-01 19:06:36,707 INFO progress=1075/20674 downloaded=1046 failed=29 speed=22.16 images/s
|
| 96 |
+
2026-09-01 19:06:37,346 INFO progress=1100/20674 downloaded=1071 failed=29 speed=22.38 images/s
|
| 97 |
+
2026-09-01 19:06:38,208 INFO progress=1125/20674 downloaded=1095 failed=30 speed=22.50 images/s
|
| 98 |
+
2026-09-01 19:06:39,232 INFO progress=1150/20674 downloaded=1119 failed=31 speed=22.54 images/s
|
| 99 |
+
2026-09-01 19:06:40,245 INFO progress=1175/20674 downloaded=1144 failed=31 speed=22.58 images/s
|
| 100 |
+
2026-09-01 19:06:41,286 INFO progress=1200/20674 downloaded=1169 failed=31 speed=22.61 images/s
|
| 101 |
+
2026-09-01 19:12:29,111 INFO prepared posts=9873 comments=78032/201544 unique_images=11239
|
| 102 |
+
2026-09-01 19:12:30,429 INFO progress=1/11239 downloaded=1 failed=0 speed=0.05 images/s
|
| 103 |
+
2026-09-01 19:12:31,819 INFO progress=25/11239 downloaded=21 failed=4 speed=1.12 images/s
|
| 104 |
+
2026-09-01 19:12:32,695 INFO progress=50/11239 downloaded=44 failed=6 speed=2.16 images/s
|
| 105 |
+
2026-09-01 19:12:36,164 INFO progress=75/11239 downloaded=63 failed=12 speed=2.81 images/s
|
| 106 |
+
2026-09-01 19:12:37,388 INFO progress=100/11239 downloaded=83 failed=17 speed=3.59 images/s
|
| 107 |
+
2026-09-01 19:12:38,027 INFO progress=125/11239 downloaded=107 failed=18 speed=4.38 images/s
|
| 108 |
+
2026-09-01 19:12:39,347 INFO progress=150/11239 downloaded=129 failed=21 speed=5.03 images/s
|
| 109 |
+
2026-09-01 19:12:41,206 INFO progress=175/11239 downloaded=151 failed=24 speed=5.52 images/s
|
| 110 |
+
2026-09-01 19:12:41,479 INFO progress=200/11239 downloaded=174 failed=26 speed=6.26 images/s
|
| 111 |
+
2026-09-01 19:12:41,990 INFO progress=225/11239 downloaded=198 failed=27 speed=6.93 images/s
|
| 112 |
+
2026-09-01 19:12:42,376 INFO progress=250/11239 downloaded=221 failed=29 speed=7.61 images/s
|
| 113 |
+
2026-09-01 19:12:43,276 INFO progress=275/11239 downloaded=246 failed=29 speed=8.15 images/s
|
| 114 |
+
2026-09-01 19:15:37,950 INFO prepared posts=9873 comments=78032/201544 unique_images=9958
|
| 115 |
+
2026-09-01 19:15:39,190 INFO progress=1/9958 downloaded=1 failed=0 speed=0.05 images/s
|
| 116 |
+
2026-09-01 19:15:40,219 INFO progress=25/9958 downloaded=25 failed=0 speed=1.19 images/s
|
| 117 |
+
2026-09-01 19:15:41,199 INFO progress=50/9958 downloaded=50 failed=0 speed=2.27 images/s
|
| 118 |
+
2026-09-01 19:15:41,730 INFO progress=75/9958 downloaded=75 failed=0 speed=3.33 images/s
|
| 119 |
+
2026-09-01 19:15:42,343 INFO progress=100/9958 downloaded=99 failed=1 speed=4.32 images/s
|
| 120 |
+
2026-09-01 19:15:43,202 INFO progress=125/9958 downloaded=124 failed=1 speed=5.20 images/s
|
| 121 |
+
2026-09-01 19:15:43,899 INFO progress=150/9958 downloaded=149 failed=1 speed=6.07 images/s
|
| 122 |
+
2026-09-01 19:15:44,624 INFO progress=175/9958 downloaded=174 failed=1 speed=6.88 images/s
|
| 123 |
+
2026-09-01 19:15:45,330 INFO progress=200/9958 downloaded=199 failed=1 speed=7.65 images/s
|
| 124 |
+
2026-09-01 19:15:46,327 INFO progress=225/9958 downloaded=222 failed=3 speed=8.29 images/s
|
| 125 |
+
2026-09-01 19:18:06,221 INFO prepared posts=9873 comments=78032/201544 unique_images=7830
|
| 126 |
+
2026-09-01 19:18:07,530 INFO progress=1/7830 downloaded=1 failed=0 speed=0.05 images/s
|
| 127 |
+
2026-09-01 19:18:08,744 INFO progress=25/7830 downloaded=24 failed=1 speed=1.22 images/s
|
| 128 |
+
2026-09-01 19:18:10,060 INFO progress=50/7830 downloaded=49 failed=1 speed=2.29 images/s
|
| 129 |
+
2026-09-01 19:18:11,298 INFO progress=75/7830 downloaded=73 failed=2 speed=3.25 images/s
|
| 130 |
+
2026-09-01 19:18:12,577 INFO progress=100/7830 downloaded=98 failed=2 speed=4.10 images/s
|
| 131 |
+
2026-09-01 19:18:13,928 INFO progress=125/7830 downloaded=123 failed=2 speed=4.86 images/s
|
| 132 |
+
2026-09-01 19:18:15,241 INFO progress=150/7830 downloaded=146 failed=4 speed=5.55 images/s
|
| 133 |
+
2026-09-01 19:18:16,514 INFO progress=175/7830 downloaded=170 failed=5 speed=6.18 images/s
|
| 134 |
+
2026-09-01 19:18:17,928 INFO progress=200/7830 downloaded=195 failed=5 speed=6.73 images/s
|
| 135 |
+
2026-09-01 19:18:19,349 INFO progress=225/7830 downloaded=218 failed=7 speed=7.22 images/s
|
| 136 |
+
2026-09-01 19:18:20,669 INFO progress=250/7830 downloaded=242 failed=8 speed=7.70 images/s
|
| 137 |
+
2026-09-01 19:18:22,157 INFO progress=275/7830 downloaded=266 failed=9 speed=8.10 images/s
|
| 138 |
+
2026-09-01 19:18:23,460 INFO progress=300/7830 downloaded=290 failed=10 speed=8.51 images/s
|
| 139 |
+
2026-09-01 19:18:24,907 INFO progress=325/7830 downloaded=315 failed=10 speed=8.85 images/s
|
| 140 |
+
2026-09-01 19:18:26,237 INFO progress=350/7830 downloaded=340 failed=10 speed=9.20 images/s
|
| 141 |
+
2026-09-01 19:18:27,506 INFO progress=375/7830 downloaded=365 failed=10 speed=9.54 images/s
|
| 142 |
+
2026-09-01 19:18:28,790 INFO progress=400/7830 downloaded=389 failed=11 speed=9.85 images/s
|
| 143 |
+
2026-09-01 19:18:30,096 INFO progress=425/7830 downloaded=413 failed=12 speed=10.14 images/s
|
| 144 |
+
2026-09-01 19:18:31,293 INFO progress=450/7830 downloaded=428 failed=22 speed=10.44 images/s
|
| 145 |
+
2026-09-01 19:18:32,613 INFO progress=475/7830 downloaded=449 failed=26 speed=10.69 images/s
|
| 146 |
+
2026-09-01 19:18:33,808 INFO progress=500/7830 downloaded=467 failed=33 speed=10.96 images/s
|
| 147 |
+
2026-09-01 19:18:35,196 INFO progress=525/7830 downloaded=488 failed=37 speed=11.17 images/s
|
| 148 |
+
2026-09-01 19:18:36,495 INFO progress=550/7830 downloaded=510 failed=40 speed=11.39 images/s
|
| 149 |
+
2026-09-01 19:18:37,780 INFO progress=575/7830 downloaded=529 failed=46 speed=11.60 images/s
|
| 150 |
+
2026-09-01 19:18:38,732 INFO progress=600/7830 downloaded=547 failed=53 speed=11.87 images/s
|
| 151 |
+
2026-09-01 19:18:39,965 INFO progress=625/7830 downloaded=566 failed=59 speed=12.07 images/s
|
| 152 |
+
2026-09-01 19:18:41,139 INFO progress=650/7830 downloaded=588 failed=62 speed=12.28 images/s
|
| 153 |
+
2026-09-01 19:18:42,388 INFO progress=675/7830 downloaded=610 failed=65 speed=12.45 images/s
|
| 154 |
+
2026-09-01 19:18:43,620 INFO progress=700/7830 downloaded=629 failed=71 speed=12.63 images/s
|
| 155 |
+
2026-09-01 19:18:44,921 INFO progress=725/7830 downloaded=649 failed=76 speed=12.78 images/s
|
| 156 |
+
2026-09-01 19:18:46,185 INFO progress=750/7830 downloaded=667 failed=83 speed=12.93 images/s
|
| 157 |
+
2026-09-01 19:18:47,371 INFO progress=775/7830 downloaded=687 failed=88 speed=13.10 images/s
|
| 158 |
+
2026-09-01 19:18:48,607 INFO progress=800/7830 downloaded=707 failed=93 speed=13.24 images/s
|
| 159 |
+
2026-09-01 19:21:33,385 INFO prepared posts=9873 comments=78032/201544 unique_images=5397
|
| 160 |
+
2026-09-01 19:21:34,745 INFO progress=1/5397 downloaded=1 failed=0 speed=0.05 images/s
|
| 161 |
+
2026-09-01 19:21:36,100 INFO progress=25/5397 downloaded=24 failed=1 speed=1.15 images/s
|
| 162 |
+
2026-09-01 19:21:37,421 INFO progress=50/5397 downloaded=49 failed=1 speed=2.17 images/s
|
| 163 |
+
2026-09-01 19:21:38,867 INFO progress=75/5397 downloaded=73 failed=2 speed=3.06 images/s
|
| 164 |
+
2026-09-01 19:21:40,266 INFO progress=100/5397 downloaded=98 failed=2 speed=3.86 images/s
|
| 165 |
+
2026-09-01 19:21:41,615 INFO progress=125/5397 downloaded=123 failed=2 speed=4.58 images/s
|
| 166 |
+
2026-09-01 19:21:43,058 INFO progress=150/5397 downloaded=146 failed=4 speed=5.22 images/s
|
| 167 |
+
2026-09-01 19:21:44,366 INFO progress=175/5397 downloaded=170 failed=5 speed=5.83 images/s
|
| 168 |
+
2026-09-01 19:21:45,770 INFO progress=200/5397 downloaded=195 failed=5 speed=6.36 images/s
|
| 169 |
+
2026-09-01 19:21:47,343 INFO progress=225/5397 downloaded=218 failed=7 speed=6.82 images/s
|
| 170 |
+
2026-09-01 19:21:48,631 INFO progress=250/5397 downloaded=242 failed=8 speed=7.29 images/s
|
| 171 |
+
2026-09-01 19:21:49,990 INFO progress=275/5397 downloaded=267 failed=8 speed=7.71 images/s
|
| 172 |
+
2026-09-01 19:21:51,269 INFO progress=300/5397 downloaded=290 failed=10 speed=8.12 images/s
|
| 173 |
+
2026-09-01 19:21:52,544 INFO progress=325/5397 downloaded=315 failed=10 speed=8.51 images/s
|
| 174 |
+
2026-09-01 19:21:53,947 INFO progress=350/5397 downloaded=340 failed=10 speed=8.84 images/s
|
| 175 |
+
2026-09-01 19:21:55,275 INFO progress=375/5397 downloaded=365 failed=10 speed=9.16 images/s
|
| 176 |
+
2026-09-01 19:21:56,572 INFO progress=400/5397 downloaded=389 failed=11 speed=9.47 images/s
|
| 177 |
+
2026-09-01 19:21:58,088 INFO progress=425/5397 downloaded=411 failed=14 speed=9.71 images/s
|
| 178 |
+
2026-09-01 19:21:59,306 INFO progress=450/5397 downloaded=428 failed=22 speed=10.01 images/s
|
| 179 |
+
2026-09-01 19:22:00,662 INFO progress=475/5397 downloaded=449 failed=26 speed=10.25 images/s
|
| 180 |
+
2026-09-01 19:22:02,008 INFO progress=500/5397 downloaded=467 failed=33 speed=10.49 images/s
|
| 181 |
+
2026-09-01 19:22:03,261 INFO progress=525/5397 downloaded=488 failed=37 speed=10.73 images/s
|
| 182 |
+
2026-09-01 19:22:04,585 INFO progress=550/5397 downloaded=509 failed=41 speed=10.94 images/s
|
| 183 |
+
2026-09-01 19:22:05,947 INFO progress=575/5397 downloaded=529 failed=46 speed=11.14 images/s
|
| 184 |
+
2026-09-01 19:22:07,282 INFO progress=600/5397 downloaded=547 failed=53 speed=11.33 images/s
|
| 185 |
+
2026-09-01 19:22:08,545 INFO progress=625/5397 downloaded=566 failed=59 speed=11.53 images/s
|
| 186 |
+
2026-09-01 19:22:10,005 INFO progress=650/5397 downloaded=588 failed=62 speed=11.68 images/s
|
| 187 |
+
2026-09-01 19:22:11,296 INFO progress=675/5397 downloaded=609 failed=66 speed=11.85 images/s
|
| 188 |
+
2026-09-01 19:22:12,397 INFO progress=700/5397 downloaded=629 failed=71 speed=12.06 images/s
|
| 189 |
+
2026-09-01 19:22:14,018 INFO progress=725/5397 downloaded=649 failed=76 speed=12.15 images/s
|
| 190 |
+
2026-09-01 19:22:15,334 INFO progress=750/5397 downloaded=667 failed=83 speed=12.29 images/s
|
| 191 |
+
2026-09-01 19:22:16,528 INFO progress=775/5397 downloaded=687 failed=88 speed=12.46 images/s
|
| 192 |
+
2026-09-01 19:22:17,937 INFO progress=800/5397 downloaded=706 failed=94 speed=12.58 images/s
|
| 193 |
+
2026-09-01 19:28:09,629 INFO prepared posts=9873 comments=78032/201544 unique_images=5397
|
| 194 |
+
2026-09-01 19:28:10,859 INFO progress=1/5397 downloaded=1 failed=0 speed=0.05 images/s
|
| 195 |
+
2026-09-01 19:28:12,362 INFO progress=25/5397 downloaded=24 failed=1 speed=1.19 images/s
|
| 196 |
+
2026-09-01 19:28:14,068 INFO progress=50/5397 downloaded=49 failed=1 speed=2.20 images/s
|
| 197 |
+
2026-09-01 19:28:15,544 INFO progress=75/5397 downloaded=73 failed=2 speed=3.10 images/s
|
| 198 |
+
2026-09-01 19:28:17,154 INFO progress=100/5397 downloaded=98 failed=2 speed=3.87 images/s
|
| 199 |
+
2026-09-01 19:28:18,659 INFO progress=125/5397 downloaded=123 failed=2 speed=4.58 images/s
|
| 200 |
+
2026-09-01 19:28:20,256 INFO progress=150/5397 downloaded=146 failed=4 speed=5.19 images/s
|
| 201 |
+
2026-09-01 19:28:21,985 INFO progress=175/5397 downloaded=170 failed=5 speed=5.71 images/s
|
| 202 |
+
2026-09-01 19:28:23,476 INFO progress=200/5397 downloaded=195 failed=5 speed=6.22 images/s
|
| 203 |
+
2026-09-01 19:28:25,111 INFO progress=225/5397 downloaded=218 failed=7 speed=6.66 images/s
|
| 204 |
+
2026-09-01 19:28:26,669 INFO progress=250/5397 downloaded=242 failed=8 speed=7.08 images/s
|
| 205 |
+
2026-09-01 19:28:28,266 INFO progress=275/5397 downloaded=266 failed=9 speed=7.45 images/s
|
| 206 |
+
2026-09-01 19:28:29,964 INFO progress=300/5397 downloaded=290 failed=10 speed=7.77 images/s
|
| 207 |
+
2026-09-01 19:28:31,712 INFO progress=325/5397 downloaded=315 failed=10 speed=8.05 images/s
|
| 208 |
+
2026-09-01 19:28:33,338 INFO progress=350/5397 downloaded=340 failed=10 speed=8.33 images/s
|
| 209 |
+
2026-09-01 19:28:35,124 INFO progress=375/5397 downloaded=365 failed=10 speed=8.56 images/s
|
| 210 |
+
2026-09-01 19:28:36,804 INFO progress=400/5397 downloaded=389 failed=11 speed=8.80 images/s
|
| 211 |
+
2026-09-01 19:28:38,505 INFO progress=425/5397 downloaded=412 failed=13 speed=9.01 images/s
|
| 212 |
+
2026-09-01 19:28:40,087 INFO progress=450/5397 downloaded=428 failed=22 speed=9.23 images/s
|
| 213 |
+
2026-09-01 19:28:41,756 INFO progress=475/5397 downloaded=449 failed=26 speed=9.42 images/s
|
| 214 |
+
2026-09-01 19:28:43,304 INFO progress=500/5397 downloaded=467 failed=33 speed=9.62 images/s
|
| 215 |
+
2026-09-01 19:28:44,744 INFO progress=525/5397 downloaded=488 failed=37 speed=9.83 images/s
|
| 216 |
+
2026-09-01 19:28:46,294 INFO progress=550/5397 downloaded=509 failed=41 speed=10.01 images/s
|
| 217 |
+
2026-09-01 19:28:47,873 INFO progress=575/5397 downloaded=529 failed=46 speed=10.17 images/s
|
| 218 |
+
2026-09-01 19:28:49,337 INFO progress=600/5397 downloaded=547 failed=53 speed=10.35 images/s
|
| 219 |
+
2026-09-01 19:28:50,670 INFO progress=625/5397 downloaded=566 failed=59 speed=10.53 images/s
|
| 220 |
+
2026-09-01 19:28:52,304 INFO progress=650/5397 downloaded=588 failed=62 speed=10.66 images/s
|
| 221 |
+
2026-09-01 19:28:53,889 INFO progress=675/5397 downloaded=609 failed=66 speed=10.79 images/s
|
| 222 |
+
2026-09-01 19:28:55,347 INFO progress=700/5397 downloaded=629 failed=71 speed=10.94 images/s
|
| 223 |
+
2026-09-01 19:28:57,053 INFO progress=725/5397 downloaded=649 failed=76 speed=11.03 images/s
|
| 224 |
+
2026-09-01 19:28:58,638 INFO progress=750/5397 downloaded=667 failed=83 speed=11.14 images/s
|
| 225 |
+
2026-09-01 19:29:00,210 INFO progress=775/5397 downloaded=687 failed=88 speed=11.25 images/s
|
| 226 |
+
2026-09-01 19:29:01,699 INFO progress=800/5397 downloaded=706 failed=94 speed=11.37 images/s
|
| 227 |
+
2026-09-01 19:34:51,713 INFO prepared posts=9873 comments=78032/201544 unique_images=5397
|
| 228 |
+
2026-09-01 19:34:54,595 INFO progress=1/5397 downloaded=1 failed=0 speed=0.04 images/s
|
| 229 |
+
2026-09-01 19:34:55,144 INFO progress=25/5397 downloaded=25 failed=0 speed=1.09 images/s
|
| 230 |
+
2026-09-01 19:34:57,237 INFO progress=50/5397 downloaded=49 failed=1 speed=1.99 images/s
|
| 231 |
+
2026-09-01 19:34:59,230 INFO progress=75/5397 downloaded=73 failed=2 speed=2.77 images/s
|
| 232 |
+
2026-09-01 19:35:01,238 INFO progress=100/5397 downloaded=98 failed=2 speed=3.44 images/s
|
| 233 |
+
2026-09-01 19:35:01,918 INFO progress=125/5397 downloaded=123 failed=2 speed=4.20 images/s
|
| 234 |
+
2026-09-01 19:35:04,227 INFO progress=150/5397 downloaded=147 failed=3 speed=4.68 images/s
|
| 235 |
+
2026-09-01 19:35:06,339 INFO progress=175/5397 downloaded=170 failed=5 speed=5.12 images/s
|
| 236 |
+
2026-09-01 19:35:08,440 INFO progress=200/5397 downloaded=195 failed=5 speed=5.51 images/s
|
| 237 |
+
2026-09-01 19:35:10,469 INFO progress=225/5397 downloaded=218 failed=7 speed=5.87 images/s
|
| 238 |
+
2026-09-01 19:35:11,240 INFO progress=250/5397 downloaded=242 failed=8 speed=6.40 images/s
|
| 239 |
+
2026-09-01 19:35:13,418 INFO progress=275/5397 downloaded=267 failed=8 speed=6.67 images/s
|
| 240 |
+
2026-09-01 19:35:15,654 INFO progress=300/5397 downloaded=290 failed=10 speed=6.90 images/s
|
| 241 |
+
2026-09-01 19:35:17,690 INFO progress=325/5397 downloaded=315 failed=10 speed=7.14 images/s
|
| 242 |
+
2026-09-01 19:35:18,353 INFO progress=350/5397 downloaded=340 failed=10 speed=7.58 images/s
|
| 243 |
+
2026-09-01 19:35:20,561 INFO progress=375/5397 downloaded=365 failed=10 speed=7.75 images/s
|
| 244 |
+
2026-09-01 19:35:22,745 INFO progress=400/5397 downloaded=389 failed=11 speed=7.91 images/s
|
| 245 |
+
2026-09-01 19:35:24,964 INFO progress=425/5397 downloaded=412 failed=13 speed=8.05 images/s
|
| 246 |
+
2026-09-01 19:35:26,810 INFO progress=450/5397 downloaded=428 failed=22 speed=8.23 images/s
|
| 247 |
+
2026-09-01 19:35:28,040 INFO progress=475/5397 downloaded=449 failed=26 speed=8.50 images/s
|
| 248 |
+
2026-09-01 19:35:30,335 INFO progress=500/5397 downloaded=469 failed=31 speed=8.60 images/s
|
| 249 |
+
2026-09-01 19:35:32,715 INFO progress=525/5397 downloaded=488 failed=37 speed=8.67 images/s
|
| 250 |
+
2026-09-01 19:35:34,893 INFO progress=550/5397 downloaded=508 failed=42 speed=8.77 images/s
|
| 251 |
+
2026-09-01 19:35:36,339 INFO progress=575/5397 downloaded=529 failed=46 speed=8.96 images/s
|
| 252 |
+
2026-09-01 19:35:38,741 INFO progress=600/5397 downloaded=547 failed=53 speed=9.01 images/s
|
| 253 |
+
2026-09-01 19:35:41,097 INFO progress=625/5397 downloaded=566 failed=59 speed=9.07 images/s
|
| 254 |
+
2026-09-01 19:35:43,373 INFO progress=650/5397 downloaded=588 failed=62 speed=9.13 images/s
|
| 255 |
+
2026-09-01 19:35:45,217 INFO progress=675/5397 downloaded=609 failed=66 speed=9.24 images/s
|
| 256 |
+
2026-09-01 19:35:46,861 INFO progress=700/5397 downloaded=629 failed=71 speed=9.37 images/s
|
| 257 |
+
2026-09-01 19:35:49,140 INFO progress=725/5397 downloaded=649 failed=76 speed=9.42 images/s
|
| 258 |
+
2026-09-01 19:35:51,201 INFO progress=750/5397 downloaded=669 failed=81 speed=9.49 images/s
|
| 259 |
+
2026-09-01 19:35:53,162 INFO progress=775/5397 downloaded=694 failed=81 speed=9.57 images/s
|
| 260 |
+
2026-09-01 19:35:54,695 INFO progress=800/5397 downloaded=713 failed=87 speed=9.69 images/s
|
| 261 |
+
2026-09-01 22:56:30,188 INFO prepared posts=9873 comments=78032/201544 unique_images=5397
|
| 262 |
+
2026-09-01 22:56:31,731 INFO progress=1/5397 downloaded=1 failed=0 speed=0.09 images/s
|
| 263 |
+
2026-09-01 22:56:31,928 INFO progress=25/5397 downloaded=25 failed=0 speed=2.25 images/s
|
| 264 |
+
2026-09-01 22:56:33,170 INFO progress=50/5397 downloaded=49 failed=1 speed=4.05 images/s
|
| 265 |
+
2026-09-01 22:56:34,382 INFO progress=75/5397 downloaded=73 failed=2 speed=5.53 images/s
|
| 266 |
+
2026-09-01 22:56:35,597 INFO progress=100/5397 downloaded=98 failed=2 speed=6.77 images/s
|
| 267 |
+
2026-09-01 22:56:35,784 INFO progress=125/5397 downloaded=123 failed=2 speed=8.36 images/s
|
| 268 |
+
2026-09-01 22:56:36,989 INFO progress=150/5397 downloaded=148 failed=2 speed=9.28 images/s
|
| 269 |
+
2026-09-01 22:56:38,215 INFO progress=175/5397 downloaded=171 failed=4 speed=10.07 images/s
|
| 270 |
+
2026-09-01 22:56:39,438 INFO progress=200/5397 downloaded=195 failed=5 speed=10.75 images/s
|
| 271 |
+
2026-09-01 22:56:40,625 INFO progress=225/5397 downloaded=218 failed=7 speed=11.37 images/s
|
| 272 |
+
2026-09-01 22:56:40,963 INFO progress=250/5397 downloaded=242 failed=8 speed=12.42 images/s
|
| 273 |
+
2026-09-01 22:56:42,121 INFO progress=275/5397 downloaded=267 failed=8 speed=12.92 images/s
|
| 274 |
+
2026-09-01 22:56:43,247 INFO progress=300/5397 downloaded=290 failed=10 speed=13.38 images/s
|
| 275 |
+
2026-09-01 22:56:44,427 INFO progress=325/5397 downloaded=315 failed=10 speed=13.77 images/s
|
| 276 |
+
2026-09-01 22:56:45,026 INFO progress=350/5397 downloaded=340 failed=10 speed=14.46 images/s
|
| 277 |
+
2026-09-01 22:56:45,975 INFO progress=375/5397 downloaded=365 failed=10 speed=14.91 images/s
|
| 278 |
+
2026-09-01 22:56:47,162 INFO progress=400/5397 downloaded=390 failed=10 speed=15.19 images/s
|
| 279 |
+
2026-09-01 22:56:48,370 INFO progress=425/5397 downloaded=414 failed=11 speed=15.43 images/s
|
| 280 |
+
2026-09-01 22:56:49,444 INFO progress=450/5397 downloaded=428 failed=22 speed=15.73 images/s
|
| 281 |
+
2026-09-01 22:56:50,313 INFO progress=475/5397 downloaded=450 failed=25 speed=16.11 images/s
|
| 282 |
+
2026-09-01 22:56:51,285 INFO progress=500/5397 downloaded=470 failed=30 speed=16.42 images/s
|
| 283 |
+
2026-09-01 22:56:52,339 INFO progress=525/5397 downloaded=488 failed=37 speed=16.66 images/s
|
| 284 |
+
2026-09-01 22:56:53,336 INFO progress=550/5397 downloaded=510 failed=40 speed=16.92 images/s
|
| 285 |
+
2026-09-01 22:56:54,377 INFO progress=575/5397 downloaded=529 failed=46 speed=17.14 images/s
|
| 286 |
+
2026-09-01 22:56:55,405 INFO progress=600/5397 downloaded=548 failed=52 speed=17.35 images/s
|
| 287 |
+
2026-09-01 22:56:56,391 INFO progress=625/5397 downloaded=566 failed=59 speed=17.57 images/s
|
| 288 |
+
2026-09-01 22:56:57,556 INFO progress=650/5397 downloaded=588 failed=62 speed=17.70 images/s
|
| 289 |
+
2026-09-01 22:56:58,620 INFO progress=675/5397 downloaded=610 failed=65 speed=17.86 images/s
|
| 290 |
+
2026-09-01 22:56:59,493 INFO progress=700/5397 downloaded=630 failed=70 speed=18.10 images/s
|
| 291 |
+
2026-09-01 22:57:00,562 INFO progress=725/5397 downloaded=650 failed=75 speed=18.25 images/s
|
| 292 |
+
2026-09-01 22:57:01,590 INFO progress=750/5397 downloaded=668 failed=82 speed=18.40 images/s
|
| 293 |
+
2026-09-01 22:57:02,720 INFO progress=775/5397 downloaded=688 failed=87 speed=18.50 images/s
|
| 294 |
+
2026-09-01 22:57:03,715 INFO progress=800/5397 downloaded=706 failed=94 speed=18.65 images/s
|
| 295 |
+
2026-09-01 22:59:22,726 INFO prepared posts=9873 comments=78032/201544 unique_images=5397
|
| 296 |
+
2026-09-01 22:59:24,311 INFO progress=1/5397 downloaded=1 failed=0 speed=0.09 images/s
|
| 297 |
+
2026-09-01 22:59:24,478 INFO progress=25/5397 downloaded=25 failed=0 speed=2.32 images/s
|
reddit/_rescue_20260917/raw/solved_whereisthis/download_state.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"status":"running","total_images":5397,"completed":25,"downloaded":25,"failed":0,"updated_at":1788274764.4783723}
|
reddit/_rescue_20260917/raw/solved_whereisthis/image_manifest.jsonl
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
reddit/_rescue_20260917/raw/solved_whereisthis/solved_comments.jsonl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:7feef1a1ca30a5dc460f2ef7f20eaf35d3d8de9113675419abc6af4519d5436f
|
| 3 |
+
size 117057811
|
reddit/_rescue_20260917/raw/solved_whereisthis/solved_posts_with_comments.jsonl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:649d72244c75d3a0396f99c15365b93566abf9d0e2fbf35086f565effa850f17
|
| 3 |
+
size 151523413
|