Created
October 26, 2020 02:15
-
-
Save Lense/02f976df85b91d34e6e997e6d13a25ab to your computer and use it in GitHub Desktop.
CTFtime scoreboard generator for CTFd
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
#!/usr/bin/python3 | |
import json | |
from CTFd import create_app | |
from CTFd.models import Users, Challenges | |
scoreboard = dict() | |
scoreboard["standings"] = list() | |
app = create_app() | |
with app.app_context(): | |
for u in Users.query.all(): | |
pos = u.get_place(numeric=True) | |
if pos == None: | |
continue | |
taskStats = {} | |
for solve in u.get_solves(): | |
taskStats[solve.challenge.name] = { | |
"points": solve.challenge.value, | |
"time": int(solve.date.timestamp()), | |
} | |
scoreboard["standings"].append( | |
{ | |
"pos": pos, | |
"team": u.name, | |
"score": u.score, | |
"taskStats": taskStats, | |
"lastAccept": max([ts["time"] for ts in taskStats.values()]), | |
} | |
) | |
scoreboard["standings"].sort(key=lambda team: team["pos"]) | |
scoreboard["tasks"] = [c.name for c in Challenges.query.all()] | |
print(json.dumps(scoreboard)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment