import sys; sys.path.insert(0, __import__('os').path.dirname(__file__)) from common import * from concurrent.futures import ThreadPoolExecutor H = "https://factorio-blueprints.com" ids = [] for i in range(20): x = get(f"{H}/sitemap-blueprints/{i}.xml") if not x: break ids += re.findall(r"https://factorio-blueprints.com/blueprint/([^<]+)", x.decode()) w = Writer("factorio-blueprints.com") todo = [i for i in dict.fromkeys(ids) if i not in w.seen] print(len(ids), "ids", len(todo), "todo", flush=True) def one(i): s = get_json(f"{H}/api/blueprint/{i}/string") s = s and (s.get("blueprint") or s.get("blueprintString")) if not s: return 0 m = get_json(f"{H}/api/blueprint/{i}") or {} return w.write({"id": i, "url": f"{H}/blueprint/{i}", "title": m.get("name"), "author": m.get("author"), "tags": m.get("tags") or [], "created": m.get("lastUpdated"), "string": s}) t = time.time(); done = 0 with ThreadPoolExecutor(12) as ex: for r in ex.map(one, todo): done += 1 if done % 500 == 0: print(done, w.n, round(time.time() - t), flush=True) w.close(); print("DONE", w.n, "new;", len(w.seen), "total", round(time.time() - t), "s", flush=True)