Created
August 1, 2022 21:37
-
-
Save arxenix/cc15fd95ee241d07c8613ac41fba9379 to your computer and use it in GitHub Desktop.
generate ctftime scoreboard json from ctfd api
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
from datetime import datetime | |
import json | |
from tqdm import tqdm | |
import sys | |
out = sys.argv[1] | |
URL = "https://2022.uiuc.tf" | |
MIN_SCORE = 0 # filter out scores at or below this value | |
ctftime = {"tasks": [], "standings": []} | |
challenges = requests.get(f"{URL}/api/v1/challenges").json() | |
for chall in challenges["data"]: | |
ctftime["tasks"].append(chall["name"]) | |
scoreboard = requests.get(f"{URL}/api/v1/scoreboard").json()["data"] | |
scoreboard = list(filter(lambda x: x["score"] > MIN_SCORE, scoreboard)) | |
for res in tqdm(scoreboard): | |
task_stats = {} | |
solves = requests.get(f"{URL}/api/v1/teams/{res['account_id']}/solves").json() | |
last_accept = -1 | |
for solve in solves["data"]: | |
chal = solve["challenge"]["name"] | |
time = int(datetime.fromisoformat(solve["date"]).timestamp()) | |
last_accept = max(last_accept, time) | |
task_stats[chal] = { | |
"points": solve["challenge"]["value"], | |
"time": time | |
} | |
team_data = { | |
"pos": res["pos"], | |
"team": res["name"], | |
"score": res["score"], | |
"taskStats": task_stats | |
} | |
if last_accept != -1: | |
team_data["lastAccept"] = last_accept | |
ctftime["standings"].append(team_data) | |
outdata = json.dumps(ctftime) | |
print(outdata) | |
f = open(sys.argv[1], "w+") | |
f.write(outdata) | |
f.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment