Dota 2 Wiki:Scripts/PlayerEarnings

from BeautifulSoup import BeautifulSoup from urllib import urlopen

class Player(object): def __init__(self): self.place = '' self.country = '' self.id = '' self.name = '' self.prize = ''

def get_info: page = urlopen('https://www.esportsearnings.com/games/231-dota-2/top-players').read soup = BeautifulSoup(page) entries = [] for row in soup.findAll('tr', {'class': 'format_row highlight'}): entry = Player entry.place = row.find('td', {'class': 'format_cell detail_list_order'}).string entry.country = row.findAll('td', {'class': 'format_cell detail_list_player'})[0].find('img')['title'] entry.id = row.findAll('td', {'class': 'format_cell detail_list_player'})[0].findAll('a')[1].string entry.name = row.findAll('td', {'class': 'format_cell detail_list_player'})[1].find('a').string entry.prize = row.find('td', {'class': 'format_cell detail_list_prize'}).string entries.append(entry) return entries

def format_output(players, limit=50, cols=5): # Remove unwanted entries. players = players[:limit] # Determine the number of players per column. offset = limit / cols # Create the output list and add the header template. output = ['🇨🇴']

for place, player in enumerate(players): place += 1 output.append('{:02d}. {} (\'\'\'{}\'\'\') '.format(place, player.country, player.id, player.prize)) # Add col breaks in the appropriate places. if place % offset == 0 and place != limit: output.append('')

# Add the footer template. output.append('')

return output

def main: players = get_info rows = format_output(players)

print '\n'.join(rows)

if __name__ == '__main__': main