outside-edge / python-espncricinfo

Python wrapper for the ESPNCricInfo JSON API
MIT License
146 stars 64 forks source link

Get Recent Matches for the day #28

Open Ehsan1997 opened 6 years ago

Ehsan1997 commented 6 years ago

Currently we get matches from the entire week. I would like to get them by days too. I wrote a script for that which I am using currently I will share it here.

Also summary.py has some problem when trying to create a Summary object.


Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "C:\Users\ehsan\AppData\Local\Programs\Python\Python36\lib\site-packages\espncricinfo\summary.py", line 7, in __init__
    self.json = self.get_json()
  File "C:\Users\ehsan\AppData\Local\Programs\Python\Python36\lib\site-packages\espncricinfo\summary.py", line 13, in get_json
    return r.json()
  File "C:\Users\ehsan\AppData\Local\Programs\Python\Python36\lib\site-packages\requests\models.py", line 896, in json
    return complexjson.loads(self.text, **kwargs)
  File "C:\Users\ehsan\AppData\Local\Programs\Python\Python36\lib\json\__init__.py", line 354, in loads
    return _default_decoder.decode(s)
  File "C:\Users\ehsan\AppData\Local\Programs\Python\Python36\lib\json\decoder.py", line 339, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\Users\ehsan\AppData\Local\Programs\Python\Python36\lib\json\decoder.py", line 357, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 2 (char 1)

Code for getting matches by the day.

    def get_recent_matches_day(date=None):
        if date:
            #date format should be YYYYmmdd e.g. 20180814
            url = "http://www.espncricinfo.com/scores/?date=date"
        else:
            url = "http://www.espncricinfo.com/scores/"
        r = requests.get(url)
        soup = BeautifulSoup(r.text, 'html.parser')
        return [x['href'].split('/', 4)[4].split('.')[0] for x in soup.findAll('a', href=True, text='SCORECARD')]
dwillis commented 6 years ago

@Ehsan1997 thanks - it looks like the Summary object json url no longer works.

scrambldchannel commented 4 years ago

Yeah, I get a 404 for the summary.json url. There is an RSS feed of current matches (http://static.cricinfo.com/rss/livescores.xml) that could be used to get current matches. I might try to knock something together to parse this if anyone's interested.

dwillis commented 4 years ago

@scrambldchannel That would be awesome, thank you!