Download scripts/blueprints/reddit_comments.py from beyarkay/factorio-blueprints: direct link, hf CLI and curl.
- Browser
- Download file 1.57 kB
-
https://huggingface.co/datasets/beyarkay/factorio-blueprints/resolve/main/scripts/blueprints/reddit_comments.py
- Command line
-
hf download hf://datasets/beyarkay/factorio-blueprints/scripts/blueprints/reddit_comments.py
-
curl -L -o reddit_comments.py https://huggingface.co/datasets/beyarkay/factorio-blueprints/resolve/main/scripts/blueprints/reddit_comments.py
1.57 kB
| # Dump posts (all fields needed for bp extraction) via Arctic Shift. argv: cache_dir name query-params... | |
| import sys; sys.path.insert(0, __import__('os').path.dirname(__file__)) | |
| from common import * | |
| A = "https://arctic-shift.photon-reddit.com/api/comments/search" | |
| cache, name, q = sys.argv[1], sys.argv[2], sys.argv[3] | |
| path = os.path.join(cache, f"comments_{name}.jsonl") | |
| after, seen = "2005-01-01", set() | |
| if os.path.exists(path): | |
| for l in open(path): | |
| try: d = json.loads(l) | |
| except Exception: continue | |
| seen.add(d["id"]); after = max(after, d["created_utc"]) if isinstance(after, int) else d["created_utc"] | |
| f = open(path, "a"); t = time.time() | |
| F = "id,created_utc,body,author,link_id,parent_id,subreddit" | |
| while True: | |
| d = None | |
| for i in range(8): | |
| b = get(f"{A}?{q}&limit=auto&sort=asc&after={after}&fields={F}", tries=3, timeout=120, ok404=False) | |
| try: d = json.loads(b) if b else None | |
| except Exception: d = None | |
| if d and d.get("data") is not None: break | |
| time.sleep(5 * (i + 1)) | |
| if not d or d.get("data") is None: print("FAILED at", after, flush=True); break | |
| rows = [r for r in d["data"] if r["id"] not in seen] | |
| if not d["data"] or not rows and len(d["data"]) < 100: break | |
| for r in rows: seen.add(r["id"]); f.write(json.dumps(r) + "\n") | |
| f.flush() | |
| after = d["data"][-1]["created_utc"] | |
| if not rows: after += 1 | |
| print(len(seen), time.strftime("%Y-%m-%d", time.gmtime(after)), round(time.time() - t), flush=True) | |
| print("DONE", len(seen), round(time.time() - t), flush=True) | |