Created
October 26, 2015 22:40
-
-
Save samliu/e21be78316884f192bf3 to your computer and use it in GitHub Desktop.
A quick script I wrote to calculate how much money we'd need to contribute to Swedish Delight's entrance to the Super Smash Brothers (game) Summit. This was a competitive donation event, so it was necessary to understand at all times how much money we'd need on hand at a minimum.
This file contains hidden or 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
# !/usr/bin/env python | |
# | |
# Initial Author: Samuel C. Liu <[email protected]> | |
# | |
# Description: Parse smash.gg to get current numbers for James. | |
# | |
# requirements.txt: | |
# beautifulsoup4 == 4.4.1 | |
from bs4 import BeautifulSoup | |
import os | |
class SnipeCalculator(object): | |
def __init__(self, filename='details'): | |
"""Load file and parse with BeautifulSoup4.""" | |
raw_html = ''.join(open(filename).readlines()) | |
soup = BeautifulSoup(raw_html, 'html.parser') | |
# Find all blocks containing each pay statement. | |
self.player_html = soup.find_all(class_="summit-player-column") | |
def display(self): | |
votes_table = {} | |
rank = 0 | |
for player in self.player_html: | |
rank += 1 | |
avatar_attachment = player.find(class_="avatar-attachment") | |
votes = avatar_attachment.find(class_="text-muted").get_text() | |
votes = int(votes.replace(',', '')) | |
votes_table[rank] = votes | |
try: | |
player_name_prefix = player.find(class_="prefix").get_text() | |
except: | |
player_name_prefix = '' | |
player_name = player.find(class_="gamertag-title-lg").get_text() | |
player_name = player_name[len(player_name_prefix):len(player_name)] | |
if player_name == 'Swedish Delight': | |
votes_needed = votes_table[1] - votes_table[rank] | |
accounts_needed = float(votes_needed / 6) | |
dollars_needed_at_5_dollar_vote = votes_needed * 5 | |
dollars_needed_at_6_votes_per_dollar = accounts_needed * 5 | |
print 'James still needs: ' + str(votes_needed) + ' votes.' | |
print '(' + str(accounts_needed) + ' accounts).' | |
print 'With all new accounts: $' + str(dollars_needed_at_6_votes_per_dollar) | |
print 'With existing contributors: $' + str(dollars_needed_at_5_dollar_vote) | |
# Uncomment this line to see everyone's standings. | |
# print player_name_prefix + ' | ' + player_name + ' (' + str(votes) + ' votes)\n\n' | |
def cli(): | |
"""Command line interface.""" | |
os.system('rm details*') | |
os.system('wget "https://smash.gg/tournament/smash-summit/details"') | |
processor = SnipeCalculator() | |
processor.display() | |
if __name__ == "__main__": | |
cli() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment