From 763379434af0566ef213816148f785f78656d549 Mon Sep 17 00:00:00 2001 From: Neale Pickett Date: Thu, 17 May 2018 21:15:53 +0000 Subject: [PATCH] Tool to fetch everything and put it in a zip file --- tools/fetch.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100755 tools/fetch.py diff --git a/tools/fetch.py b/tools/fetch.py new file mode 100755 index 0000000..901a1c8 --- /dev/null +++ b/tools/fetch.py @@ -0,0 +1,29 @@ +#! /usr/bin/python3 + +import requests +import zipfile + +url = "https://puzzles.cyberfire.training/foundry/" +url = url.rstrip("/") + +r = requests.get(url + "/puzzles.json") +puzzles = r.json() + +zf = zipfile.ZipFile("/tmp/foundry.zip", "w") +for cat, entries in puzzles.items(): + if cat == "wopr": + continue + + for points, dn in entries: + if points == 0: + continue + u = "{}/{}/{}/puzzle.json".format(url, cat, dn) + + print(u, points, dn) + obj = requests.get(u).json() + files = obj.get("files") + ["index.html"] + + for fn in files: + path = "{}/{}/{}".format(cat, points, fn) + data = requests.get(u).content + zf.writestr(path, data)