Skip to content

Commit 0d81c05

Browse files
committed
Add scoreboard 2 ctftime script
1 parent 8322159 commit 0d81c05

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

scoreboard2ctftime.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env python3
2+
import time
3+
import requests
4+
import json
5+
6+
ENOWARS_URL = "https://9.enowars.com/scoreboard/scoreboard.json"
7+
EXCLUDED_TEAMS = ["ENOOPFLAG"]
8+
9+
def fetch_enowars():
10+
resp = requests.get(ENOWARS_URL)
11+
resp.raise_for_status()
12+
return resp.json()
13+
14+
def to_ctftime_feed(enowars_json):
15+
teams = enowars_json.get("teams", [])
16+
feed = {
17+
"standings": []
18+
}
19+
20+
ranking = 1
21+
for idx, team in enumerate(sorted(teams, key=lambda t: t["totalScore"], reverse=True)):
22+
if team['teamName'].lower() in list(map(lambda x: x.lower(), EXCLUDED_TEAMS)):
23+
continue
24+
entry = {
25+
"pos": ranking,
26+
"team": team["teamName"],
27+
"score": round(team["totalScore"], 4)
28+
}
29+
feed["standings"].append(entry)
30+
ranking +=1
31+
return feed
32+
33+
def main():
34+
enowars = fetch_enowars()
35+
ctftime = to_ctftime_feed(enowars)
36+
print(json.dumps(ctftime, indent=2))
37+
with open("scoreboard.json", "w") as f:
38+
json.dump(ctftime, f, indent=2)
39+
40+
if __name__ == "__main__":
41+
main()

0 commit comments

Comments
 (0)