Created
October 28, 2021 22:28
-
-
Save Nevexo/146ef2b4be881f74dcfea5a9d2cb7a23 to your computer and use it in GitHub Desktop.
4wc-stats
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 | |
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