beyarkay's picture
Blueprints from 11 sites + 31 save files
02f8da8 verified
Raw History Blame Contribute Delete
1.58 kB
# factorioblueprints.tech: page ids from SSR listing (?page=N), metadata + string from its workers API.
import sys; sys.path.insert(0, __import__('os').path.dirname(__file__))
from common import *
from concurrent.futures import ThreadPoolExecutor
H = "https://factorioblueprints.tech"; W = "https://factorio-blueprints-workers-api.factorio.workers.dev"
def listing(p):
b = get(f"{H}/?page={p}")
return list(dict.fromkeys(re.findall(r'href="/page/([0-9a-f-]{36})', b.decode()))) if b else []
ids, p = [], 1
with ThreadPoolExecutor(6) as ex:
while True:
res = list(ex.map(listing, range(p, p + 12))); p += 12
for r in res: ids += r
if not any(res): break
ids = list(dict.fromkeys(ids)); print(len(ids), "pages listed, last page <", p, flush=True)
w = Writer("factorioblueprints.tech")
def one(i):
if i in w.seen: return
d = (get_json(f"{W}/blueprint_page/{i}") or {}).get("data") or {}
bp = d.get("blueprintPage") or {}
s = None
if bp.get("blueprintBookId"): s = (get_json(f"{W}/string/blueprint_book/{bp['blueprintBookId']}") or {}).get("data")
elif bp.get("blueprintId"): s = (get_json(f"{W}/string/blueprint/{bp['blueprintId']}") or {}).get("data")
w.write({"id": i, "url": f"{H}/page/{i}", "title": bp.get("title"), "author": bp.get("userName") or bp.get("userId"),
"tags": bp.get("tags") or [], "created": bp.get("createdAt"), "string": s})
t0 = time.time()
with ThreadPoolExecutor(8) as ex: list(ex.map(one, ids))
w.close(); print("DONE", w.n, len(w.seen), round(time.time() - t0), "s", flush=True)