Created
April 16, 2016 18:20
-
-
Save ejmurray/21b8578182d67864dfb67dfed0c5a67a to your computer and use it in GitHub Desktop.
Scores.py
This file contains 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
# coding: utf-8 | |
''' | |
Created on Jan 17, 2016 | |
@author: timbo | |
''' | |
import requests | |
from urllib.request import urlopen | |
from bs4 import BeautifulSoup #Needed to parse the html | |
import time | |
# enter URL of game you want to track | |
url = 'http://www.cbssports.com/nfl/gametracker/live/NFL_20160117_PIT@DEN' | |
def check_score(): | |
gamecenter = BeautifulSoup(urlopen(url),'html.parser') #get the data from the page | |
visitor = gamecenter.findAll('div', class_="hud-team away") # get the data on the visiting team | |
vteam = visitor[0].findAll('div',class_='team') # Visiting team name | |
vscore = visitor[0].findAll('div',class_='score') # Visiting team score | |
vposs = visitor[0].findAll('li',class_="poss current") # visiting team possession status | |
home = gamecenter.findAll('div', class_="hud-team home") # home team data | |
hteam = home[0].findAll('div',class_='team') # home team name | |
hscore = home[0].findAll('div',class_='score') # home team score | |
hposs = home[0].findAll('li',class_="poss current") # home team possession status | |
situation = gamecenter.findAll('div', class_="hud-status") # game status | |
print((vteam[0].text).strip(),int(vscore[0].text)) # Print visiting team name and score | |
print((hteam[0].text).strip(),int(hscore[0].text)) # print home team name and score | |
print((situation[0].text).strip()) # print game situation | |
time_left = situation[0].findAll('p',class_='status') # Check whether game is over | |
while True: | |
if time_left[0].text == 'Final': | |
break | |
else: | |
if len(vposs) > 0: | |
print((vteam[0].text).strip(),'ball') | |
else: | |
print((hteam[0].text).strip(),'ball') | |
time.sleep(30) | |
check_score() | |
check_score() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment