Skip to content

Instantly share code, notes, and snippets.

@Nevexo
Created October 28, 2021 22:28
Show Gist options
  • Save Nevexo/146ef2b4be881f74dcfea5a9d2cb7a23 to your computer and use it in GitHub Desktop.
Save Nevexo/146ef2b4be881f74dcfea5a9d2cb7a23 to your computer and use it in GitHub Desktop.
4wc-stats
import requests
BASE_URL = ""
# god this code is so bad
print("Requesting...")
r = requests.get(f"{BASE_URL}/getScoreBoard")
if r.status_code != 200:
print(r.status_code)
exit(1)
data = r.text.split("\n")
data.pop(0)
scores = []
for line in data:
row = line.split('","')
score_data = []
for x in row:
score_data.append(x.strip().replace('"', ''))
scores.append(score_data)
# Print current scores
for line in scores:
# Actually awful, but whatever.
print(f"--\n๐Ÿคทโ€โ™‚๏ธ User: {line[0]}\n "
f"-> ๐Ÿ”Ž Questions Answered: {line[2]}\n "
f"-> โœ Current Score: {line[1]}\n "
f"-> ๐Ÿ“š Quiz Category: {line[3]}")
print("\n---- [ S T A T S ] ----")
# Stats collection
categories = {}
highest_score = -1
highest_score_user = "nobody?"
most_questions_answered = -1
most_questions_user = "nobody?"
for line in scores:
if line[3] not in categories:
categories[line[3]] = 1
else:
categories[line[3]] += 1
if float(line[1]) > highest_score:
highest_score = float(line[1])
highest_score_user = line[0]
if float(line[2]) > most_questions_answered:
most_questions_answered = float(line[2])
most_questions_user = line[0]
print("๐Ÿ“š Most Used Categories: ")
for attr, value in categories.items():
print(f" -> {attr}: {value}")
print("\n๐Ÿ‘ Highest Score:")
print(f" -> {highest_score_user} ({highest_score} points)")
print("\n๐Ÿ‘ Most Questions Answered: ")
print(f" -> {most_questions_user} ({most_questions_answered} questions)")
print("\n๐Ÿ‘€ Number of Participants")
print(f" -> {len(scores)}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment