-
Notifications
You must be signed in to change notification settings - Fork 112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Trying to print all games in current month #86
Comments
In [2]: from __future__ import print_function
...: import mlbgame
...: import datetime
...: year = datetime.date.today().year
...: month = datetime.date.today().month
...: new_month = mlbgame.games(year,month,home='Red Sox', away='Red Sox')
...: print(new_month)
...: games = mlbgame.combine_games(new_month)
...: for game in games:
...: print(game)
...:
Red Sox (2) at Rays (1)
Red Sox (7) at Marlins (3)
Red Sox (4) at Marlins (2)
Rays (2) at Red Sox (3)
Rays (0) at Red Sox (0)
Rays (0) at Red Sox (0)
Yankees (0) at Red Sox (0)
Yankees (0) at Red Sox (0)
Yankees (0) at Red Sox (0)
Orioles (0) at Red Sox (0)
Orioles (0) at Red Sox (0)
Orioles (0) at Red Sox (0)
Orioles (0) at Red Sox (0)
Red Sox (0) at Angels (0)
Red Sox (0) at Angels (0)
Red Sox (0) at Angels (0)
Red Sox (0) at Athletics (0)
Red Sox (0) at Athletics (0)
Red Sox (0) at Athletics (0)
Red Sox (0) at Blue Jays (0)
Red Sox (0) at Blue Jays (0)
Red Sox (0) at Blue Jays (0)
Rays (0) at Red Sox (0)
Rays (0) at Red Sox (0)
Rays (0) at Red Sox (0)
Royals (0) at Red Sox (0) It takes a while, but it looks like it runs. Part of the slowness is likely due to sequential downloads. I have some ideas to drastically speed that up, but I have some other PRs to finish before I could get to that. |
@trevor-viljoen just from looking at this in the browser, the actual gd2.mlb.com API is taking a long time for 2018 games. Is there a more efficient way to query the API for a range of dates rather than day by day. I'm happy to take a look at this/help contribute |
@PeterKaminski09 I haven't had time to dig into #90. I'd like to implement the requests library to use sessions and with that, https://github.com/reclosedev/requests-cache. This would help in reducing the bandwidth required, particularly for completed games. Additionally, this would help with an issue that was brought up by the MLB-LED-Scoreboard project. They sometimes experience an error related to open connections.
In your case some local caching using something like Redis might be useful. I recently had to do something similar for another project I'm working on. The work flow is as follows:
As for a more efficient way to query for a range of dates, that depends on what data you actually need. |
@trevor-viljoen I used to have a method for caching XML files but as the library expanded I found it to be too hard to maintain. However, if you can come up with a better method for caching then I would be glad to accept a PR. |
Hi, I am trying to do something similar to what is on the documentation with printing games, but I have used datetime to get the current month and year and use that to build the list of upcoming and recent games. However, whenever I try to print anything in the future or current timeframe, the line that calls mlbgame.games() does not ever complete running.
Here is what I have:
from __future__ import print_function
import mlbgame
import datetime
year = datetime.date.today().year
month = datetime.date.today().month
new_month = mlbgame.games(year,month,home='Red Sox', away='Red Sox')
games = mlbgame.combine_games(new_month)
for game in games:
print(game)
The text was updated successfully, but these errors were encountered: