Skip to content

Instantly share code, notes, and snippets.

@Lense
Created October 26, 2020 02:15
Show Gist options
  • Save Lense/02f976df85b91d34e6e997e6d13a25ab to your computer and use it in GitHub Desktop.
Save Lense/02f976df85b91d34e6e997e6d13a25ab to your computer and use it in GitHub Desktop.
CTFtime scoreboard generator for CTFd
#!/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