diff --git a/espncricinfo/summary.py b/espncricinfo/summary.py index a8fcee4..b4148ac 100644 --- a/espncricinfo/summary.py +++ b/espncricinfo/summary.py @@ -1,18 +1,29 @@ import requests +from xml.etree import ElementTree as ET class Summary(object): def __init__(self): - self.url = "http://www.espncricinfo.com/netstorage/summary.json" - self.json = self.get_json() - self.match_ids = self.json['matches'].keys() - self.all_matches = self.json['matches'].values() + self.url = "http://static.cricinfo.com/rss/livescores.xml" + self.rss = self.get_rss() + + self.matches = {} + self.match_ids = [] - def get_json(self): - r = requests.get(self.url) - return r.json() + if len(self.rss) > 0: + + for i in self.rss[0].findall('item'): + desc = i.find('description').text + guid = i.find('guid').text + match_id = guid.split('/')[-1].split('.')[0] + self.matches[match_id] = {'description' : desc, 'url' : guid} + + self.match_ids = list(self.matches.keys()) - def match(self, id): - m = self.json['matches'][id] - m['url'] = "http://www.espncricinfo.com"+m['url'] - return m + def get_rss(self): + + r = requests.get(self.url) + if r.ok: + return ET.fromstring(r.content) + else: + return None