evansloan / sports.py

A simple Python package to gather live sports scores
MIT License
60 stars 17 forks source link

Live matches don't show up correctly? #2

Closed toddpt14 closed 5 years ago

toddpt14 commented 5 years ago

I can't tell if it's me, but all the live matches that are displayed on sports.all_matches() are all finished. Maybe I'm using this incorrectly? Is there a way to figure out exactly what link it uses for data?

evansloan commented 5 years ago

Would you mind sharing the code where you use sports.all_matches()? I'm not able to reproduce your problem.

Here are the results I'm getting:

>>> import sports
>>> all_matches = sports.all_matches()
>>> for sport, matches in all_matches.items():
...     print(sport)
...     for match in matches:
...             print(f'\t{match.match_time}')
...
baseball
    4 Inn
    3 Inn
    Match Finished
    Match Finished
    Match Finished
    Match Finished
    Match Finished
    Match Finished
    Match Finished
    Match Finished
basketball
    4th Quarter
    4th Quarter
    3rd Quarter
    Halftime
    Overtime
    Halftime
    Aw
    Match Finished
    Match Finished
    Match Finished
cricket
    Match Finished
    Match Abandoned
    Match Abandoned
    Match Finished
    Match Finished
    Match Finished
    Match Abandoned
    Match Abandoned
    Match Abandoned
    Match Abandoned
football
handball
    1st Half
    2nd Half
    2nd Half
    2nd Half
    2nd Half
    1st Half
    2nd Half
    1st Half
    1st Half
    2nd Half
hockey
    1st Period
    E/p2
    E/p2
    Match Finished
    Match Finished
    Match Finished
    Match Finished
    Match Finished
    Match Finished
    Match Finished
rugby-league
    Match Finished
rugby-union
    Match Finished
soccer
    2nd Half Started
    Match Finished
    Match Finished
    Match Finished
    Match Finished
tennis
    1st Set
    2nd Set
    1st Set
    1st Set
    1st Set
    Match Finished
    Match Finished
    Match Finished
    Match Finished
    Match Finished
volleyball
    3rd Set
    3rd Set
    4th Set
    2nd Set
    Match Finished
    Match Finished
    Match Finished
    Match Finished
    Match Finished
    Match Finished
toddpt14 commented 5 years ago

I can't even run the all_matches = sports.all_matches() which is weird considering I just ran it a few hours ago and got results similar to yours, but didn't check if matches were live. I've also been pretty successful with this program for the last month, so it might just be me and my environment I messed up.

Here's what I get now, May 9th 22:45 GMT. I'm timestamping this, because maybe the service feed is down and that's why I get None returned?

In [1]: import sports In [2]: all_matches = sports.all_matches()


AttributeError Traceback (most recent call last)

in () ----> 1 all_matches = sports.all_matches() ~/anaconda3/lib/python3.6/site-packages/sports/scores.py in all_matches() 166 :rtype: dict 167 """ --> 168 return {sport: get_sport(sport) for sport in constants.SPORTS} ~/anaconda3/lib/python3.6/site-packages/sports/scores.py in (.0) 166 :rtype: dict 167 """ --> 168 return {sport: get_sport(sport) for sport in constants.SPORTS} ~/anaconda3/lib/python3.6/site-packages/sports/scores.py in get_sport(sport) 117 if sport == constants.SOCCER: 118 desc = match.find('description').text --> 119 match_info = _parse_match_info(desc, soccer=True) 120 else: 121 desc = match.find('title').text ~/anaconda3/lib/python3.6/site-packages/sports/scores.py in _parse_match_info(match, soccer) 78 match_info = {} 79 ---> 80 i_open = match.index('(') 81 i_close = match.index(')') 82 match_info['league'] = match[i_open + 1:i_close].strip() AttributeError: 'NoneType' object has no attribute 'index' 20 minutes later I get this now: In [1]: import sports In [2]: all_matches = sports.all_matches() Traceback (most recent call last): File "", line 1, in File "~/anaconda3/lib/python3.6/site-packages/sports/scores.py", line 168, in all_matches return {sport: get_sport(sport) for sport in constants.SPORTS} File "~/anaconda3/lib/python3.6/site-packages/sports/scores.py", line 168, in return {sport: get_sport(sport) for sport in constants.SPORTS} File "~/anaconda3/lib/python3.6/site-packages/sports/scores.py", line 119, in get_sport match_info = _parse_match_info(desc, soccer=True) File "~/anaconda3/lib/python3.6/site-packages/sports/scores.py", line 80, in _parse_match_info i_open = match.index('(') ValueError: substring not found
evansloan commented 5 years ago

Sorry for the late response. It seems to be getting hung up when trying to get the results for soccer games. It fetches the results from this XML page.

It looks like they changed to structure of the soccer XML just enough to beak the parser that pulls out all the match details. I'll try to push out an update to get around this tonight.

evansloan commented 5 years ago

I've pushed out an update now, you should be able to install it with pip install -U sports.py

There is still an issue with getting the match time for soccer matches. For whatever reason it is not being included in the XML page I linked in my comment above. Unfortunately that is out of my control.

EDIT: And they've changed the structure again, breaking the changes I made. I'll try to figure something out here.

evansloan commented 5 years ago

The most recent update should be able to handle the two XML structures they seem to be going back and forth with on with soccer games.