/boxscores

Generates daily emails with NBA and/or MLB boxscores, standings, and stat leaders.

Primary LanguagePython

boxscores

Generates daily emails with NBA and/or MLB boxscores, standings, and stat leaders.

XML Stats

This application uses Erik Berg's XML Stats API service to build and format emails with the previous day's boxscores for MLB and NBA games, along with current team standings and individual stat leaders.

Please adhere to the XML Stats API guidelines to play nice with the API. This application builds in many 10 second pauses to stay under the rate limit, meaning it takes several minutes for the program to complete its run.

Also, note that XML Stats API requires its access token to be manually refreshed on the site every 30 days or it will expire. Upon refresh, you must replace the token in your code with the new one you obtain. (The token should be placed in xmlstats.py in place of 'YOUR_XMLSTATS_TOKEN.')

Dependencies

If using Google Sheets for MLB Stat Leaders (see disclaimer below), you'll also need the following libraries:

Operation

Emails are generated by two scripts:

  1. bbemail.py - builds and sends an MLB email
  2. nbaemail.py - builds and sends an NBA email

To set up automatic daily emails, create a cron job to run each script at a specified time.

In the email scripts, you will need to replace several placeholders with your own information:

addr_to = [YOUR_EMAIL_ADDRESS]

addr_from = 'Python Baseball Times <[YOUR_FROM_EMAIL_ADDRESS]>'

smtp_server = [YOUR_SMTP_SERVER]

smtp_user = [YOUR_SMTP_USERNAME]

smtp_pass = [YOUR_SMTP_PASSWORD]

Disclaimer About MLB Stat Leaders

The XML Stats API does not provide individual stat leader data for MLB. Instead I obtain this data via Google Sheets, which in turn obtains it from custom statistical views I created on Fangraphs. If you wish to replicate this, you'll need to build your own Fangraph views and Google Sheet and then customize leaders.py to use your Sheet.

If you do not plan to set up Google Sheets for this purpose, be sure to delete/comment out this line from bbemail.py:

html += leaders()

NBA stat leader and daily leader info is obtained directly from XML Stats API and does not require further customization