Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Avinash-Raj/b0edbd61c349cbeb8e20 to your computer and use it in GitHub Desktop.
Save Avinash-Raj/b0edbd61c349cbeb8e20 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# Here is the python2 script to see StackOverflow 2015 election candidates who're going to the next phase along with their vote-counts.
# For this script to work, you must need to install Python's BeautifulSoup html parser.
# Created by Stack Overflow user Avinash Raj ( http://stackoverflow.com/users/3297613/avinash-raj )
from bs4 import BeautifulSoup
import urllib2
s = urllib2.urlopen('http://stackoverflow.com/election/6?tab=primary')
soup = BeautifulSoup(s)
vote_count = [i.text for i in soup.select('tr[id^="post"] span.vote-count-post')]
user_name = [i.text for i in soup.select('tr[id^="post"] div.user-details a')]
print "<---- Candidates who goes to the next election phase ---->"
m = sorted(zip(user_name,vote_count), key= lambda x: int(x[1]), reverse=True)
for x,y in m[:10]:
print '{:<16}{:>20}'.format(x,y)
print "<-------------------------------------------------------->"
for x,y in m[10:]:
print '{:<16}{:>20}'.format(x,y)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment