Skip to content

Instantly share code, notes, and snippets.

@jinnosux
Last active December 17, 2023 00:04
Show Gist options
  • Save jinnosux/dcd8cc8f1dc761760e278e86c8cc70bc to your computer and use it in GitHub Desktop.
Save jinnosux/dcd8cc8f1dc761760e278e86c8cc70bc to your computer and use it in GitHub Desktop.
NGAwards2023 vote counting script
import xlsxwriter
from collections import Counter
import re
workbook = xlsxwriter.Workbook("example.xlsx")
worksheet = workbook.add_worksheet()
categories = ['Best Cop', 'Best Paramedic',
'Best Hitman', 'Best Gunrunner', 'Best Thief',
'Best Driver', 'Best Pilot', 'Best Disappearer', 'Best Dressed Player',
'Best Gold Rush Finder', 'Funniest Player', 'Most Helpful Player',
'Best New Player', 'NG Couple', 'Server Bitch',
'Biggest Legion Square Disruptor (Biggest Asshole)', 'Biggest Tryhard', 'Biggest Rager', '#LegionSquarePromotionOfPeaceAward',
'Most Friendly Admin', 'Most Effective Admin', 'Most Abusive Admin', 'Favorite Vehicle', 'Best NG Video',
'Best New Feature', 'Feature to Throw Away', 'Best DJ']
def extract_base_nickname(nickname):
# Extract base nickname by removing numbers and underscores
return re.sub(r'[\d_]', '', nickname).lower()
def search_str(word, col):
with open("file.txt", 'r', encoding="utf8") as file:
votes = []
for line in file:
if word in line:
try:
vote_value = line.split(word + ":")[-1].strip('-').strip()
if vote_value:
base_nickname = extract_base_nickname(vote_value)
if base_nickname:
votes.append(base_nickname)
except IndexError:
pass
# Count occurrences of each non-empty, case-insensitive vote
vote_counter = Counter(vote for vote in votes if vote not in ["", "-", " ", "/"])
# Get 1st, 2nd, and 3rd most common votes
most_common_votes = vote_counter.most_common(3)
# Write 1st, 2nd, and 3rd columns
worksheet.write(col, 0, word)
for i, (vote, count) in enumerate(most_common_votes):
worksheet.write(col, i + 1, f"{vote} ({count} votes)")
# Write all votes starting from column E
worksheet.write_row(col, 4, votes)
# Print the number of votes processed
print(f"{word}: {len(votes)} votes processed")
col = 0
for category in categories:
search_str(category, col)
col += 1
workbook.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment