Skip to content

Instantly share code, notes, and snippets.

@bycoffe
Created March 19, 2010 17:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bycoffe/337853 to your computer and use it in GitHub Desktop.
Save bycoffe/337853 to your computer and use it in GitHub Desktop.
Script to allow viewing of scores of in-progress college basketball games on the command line
#!/usr/bin/env python
"""
Python script to allow viewing of scores of in-progress college basketball games
on the command line. Scores come from Yahoo Sports.
Requirements:
BeautifulSoup
"""
import re
import urllib2
from BeautifulSoup import BeautifulSoup
def print_scores():
url = 'http://rivals.yahoo.com/ncaa/basketball/scoreboard'
soup = BeautifulSoup(urllib2.urlopen(url))
scoretables = soup.findAll('table', {'class': 'scores'})
for table in scoretables:
team1row = table.findAll('tr')[-4]
team1 = team1row.find('a').renderContents()
team1score = team1row.find('span', {'class': 'yspscores'}).renderContents()
if re.search(r'\d\d(am|pm)', team1score):
continue
timeleft = team1row.findAll('span', {'class': 'yspscores'})[-1].renderContents()
team2row = table.findAll('tr')[-2]
team2 = team2row.find('a').renderContents()
team2score = team2row.find('span', {'class': 'yspscores'}).renderContents()
half = team2row.findAll('span', {'class': 'yspscores'})[-1].renderContents()
print '%s%s%s' % (team1, ' ' * (25 - len(team1)), team1score)
print '%s%s%s' % (team2, ' ' * (25 - len(team2)), team2score)
print '%s%s%s' % (timeleft, ' ' * (25 - len(timeleft)), half)
print '-' * 40
if __name__ == '__main__':
print_scores()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment