Skip to content

Instantly share code, notes, and snippets.

Created October 20, 2014 02:10
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 anonymous/480bd2041bd9f3c891c2 to your computer and use it in GitHub Desktop.
Save anonymous/480bd2041bd9f3c891c2 to your computer and use it in GitHub Desktop.
import xml.etree.ElementTree as et
import urllib
import csv
feed = urllib.urlopen("https://api.sportsdatallc.org/ncaafb-rt1/2014/REG/schedule.xml?api_key=a3cctrtbt5sxtjgar9hjeemd")
raw_data = et.parse(feed)
root = raw_data.getroot()
feedlink = '{http://feed.elasticstats.com/schema/ncaafb/schedule-v1.0.xsd}'
results = [['week', 'gameid', 'scheduled', 'coverage', 'homerot', 'awayrot', 'home', 'away', 'status', 'venueid', 'country', 'name', 'city', 'state', 'capacity', 'surface', 'surftype', 'zipcode', 'address', 'temperature', 'condition', 'humidity', 'speed', 'direction', 'speed', 'direction', 'network', 'satellite', 'internet', 'cable', 'stats', 'href']]
for week in root.iter(tag = feedlink +'week'):
week = week.get('week')
for game in root.iter(tag = feedlink +'game'):
gameid = game.get('id')
scheduled = game.get('scheduled')
coverage = game.get('coverage')
homerot = game.get('home_rotation')
awayrot = game.get('away_rotation')
home = game.get('home')
away = game.get('away')
status = game.get('status')
print "Week: %r." % week
print "GameID: %r." % gameid
print "Scheduled: %r." % scheduled
print "Coverage: %r." % coverage
print "HomeRot: %r." % homerot
print "AwayRot: %r." % awayrot
print "Home: %r." % home
print "Away: %r." % away
print "Status: %r." % status
for venue in game.iter(tag = feedlink +'venue'):
venueid = venue.get('id')
country = venue.get('country')
name = venue.get('name')
city = venue.get('city')
state = venue.get('state')
capacity = venue.get('capacity')
surface = venue.get('surface')
surtype = venue.get('type')
zipcode = venue.get('zip')
address = venue.get('address')
print "Venue: %r." % venueid
print "Country: %r." % country
print "Name: %r." % name
print "City: %r." % city
print "State: %r." % state
print "Capacity: %r." % capacity
print "Surface: %r." % surface
print "Surface Type: %r." % surtype
print "Zip: %r." % zipcode
print "Address: %r." % address
for weather in game.iter(tag = feedlink +'weather'):
temperature = weather.get('temperature')
condition = weather.get('condition')
humidity = weather.get('humidity')
speed = weather.get('speed')
direction = weather.get('direction')
print "Temperature: %r." % temperature
print "Condition: %r." % condition
print "Humidity: %r." % humidity
for wind in game.iter(tag = feedlink +'wind'):
wind_speed = wind.get('speed')
wind_direction = wind.get('direction')
print "Speed: %r." % speed
print "Direction: %r." % direction
for broadcast in game.iter(tag = feedlink +'broadcast'):
network = broadcast.get('network')
satellite = broadcast.get('satellite')
internet = broadcast.get('internet')
cable = broadcast.get('cable')
print "Network: %r." % network
print "Satellite: %r." % satellite
print "Internet: %r." % internet
print "Cable: %r." % cable
for link in game.iter(tag = feedlink +'link'):
stats = link.get('rel')
href = link.get('href')
print "Rel: %r." % stats
print "Href: %r." % href
links=","+stats+","+href
results.append([week, game, gameid, scheduled, coverage, homerot, awayrot, home, away, status, venueid, country, name, city, state, capacity, surface, surtype, zipcode, address, temperature, condition, humidity, speed, direction, wind_speed, wind_direction, network, satellite, internet, cable, stats, href])
# Save to csv
with open('NCAA.csv', 'wb') as f:
writer = csv.writer(f)
writer.writerows(results)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment