Skip to content

Instantly share code, notes, and snippets.

@michael-lazar
Created August 20, 2013 04:00
Show Gist options
  • Save michael-lazar/6276980 to your computer and use it in GitHub Desktop.
Save michael-lazar/6276980 to your computer and use it in GitHub Desktop.
import time
import os.path
import xml.etree.ElementTree as ET
import requests
URL = 'http://xml.pinnaclesports.com/pinnacleFeed.aspx'
PARAMS = {'sportType':'E sports'}
def build_xml(filename):
# Download the feed
r = requests.get(URL,params=PARAMS)
# Parse content into an element tree
feed = ET.fromstring(r.content)
tree = ET.ElementTree(feed)
# Add a copy of the PinnacleFeedTime to each event
for event in feed.find('events'):
print event.findtext('gamenumber')
event.append(feed.find('PinnacleFeedTime'))
# Save the modified feed
tree.write(filename)
def update_xml(filename):
# Load the master record
tree = ET.parse(filename)
master_feed = tree.getroot()
# Download the feed using lastGame as a parameter
params = PARAMS
params['lastGame'] = master_feed.findtext('lastGame')
r = requests.get(URL,params=params)
# Parse content into an element
feed = ET.fromstring(r.content)
# Add a copy of the PinnacleFeedTime to each event
# Add each new event to the master feed
for event in feed.find('events'):
print event.findtext('gamenumber')
event.append(feed.find('PinnacleFeedTime'))
master_tree.find('events').append(event)
# Update fields in the master feed
master_feed.find('lastGame').text = feed.findtext('lastGame')
master_feed.find('lastContest').text = feed.findtext('lastContest')
master_feed.find('PinnacleFeedTime').text = feed.findtext('PinnacleFeedTime')
# Save the modified feed
tree.write(filename)
def main(filename):
if not os.path.isfile(filename):
build_xml(filename)
time.sleep(60)
while 1:
update_xml(filename)
time.sleep(60)
if __name__ == '__main__':
main('esports.xml')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment