2018-05-17 15:15:53 -06:00
|
|
|
#! /usr/bin/python3
|
|
|
|
|
|
|
|
import requests
|
|
|
|
import zipfile
|
|
|
|
|
2018-06-06 06:52:19 -06:00
|
|
|
instance = "foundry"
|
|
|
|
|
|
|
|
url = "https://puzzles.cyberfire.training/{}/".format(instance)
|
2018-05-17 15:15:53 -06:00
|
|
|
url = url.rstrip("/")
|
|
|
|
|
|
|
|
r = requests.get(url + "/puzzles.json")
|
|
|
|
puzzles = r.json()
|
|
|
|
|
2018-06-06 06:52:19 -06:00
|
|
|
zf = zipfile.ZipFile("/tmp/{}.zip".format(instance), "w")
|
2018-05-17 15:15:53 -06:00
|
|
|
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)
|
2018-06-06 06:52:19 -06:00
|
|
|
furl="{}/{}/{}/{}".format(url, cat, dn, fn)
|
|
|
|
data = requests.get(furl).content
|
2018-05-17 15:15:53 -06:00
|
|
|
zf.writestr(path, data)
|