Skip to content
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

Add important dates feature #85

Merged
merged 21 commits into from
Apr 9, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use year int rather than datetime object
  • Loading branch information
trevor-viljoen committed Apr 1, 2018

Unverified

This user has not yet uploaded their public signing key.
commit 19458a2cacc6e77a05419c59b6f2190bb46de83f
2 changes: 1 addition & 1 deletion mlbgame/__init__.py
Original file line number Diff line number Diff line change
@@ -228,7 +228,7 @@ def game_events(game_id):
return [mlbgame.events.Inning(data[x], x) for x in data]


def important_dates(date=datetime.now()):
def important_dates(year=datetime.now().year):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest using year=None here and then assigning year to datetime.now().year in the function body if None is passed in.

The way it's currently done the default value for year will be calculated at import time.

"""Return ImportantDates object that contains MLB important dates"""
data = mlbgame.info.important_dates(date)
return mlbgame.info.ImportantDates(data)
5 changes: 2 additions & 3 deletions mlbgame/data.py
Original file line number Diff line number Diff line change
@@ -6,7 +6,6 @@
"""

import os
from datetime import datetime
try:
from urllib.request import urlopen
from urllib.error import HTTPError
@@ -32,9 +31,9 @@
PWD = os.path.join(os.path.dirname(__file__))


def get_important_dates(date):
def get_important_dates(year):
try:
return urlopen(IMPORTANT_DATES.format(date.year))
return urlopen(IMPORTANT_DATES.format(year))
except HTTPError:
raise ValueError('Could not retrive the MLB important dates information.')

4 changes: 2 additions & 2 deletions mlbgame/info.py
Original file line number Diff line number Diff line change
@@ -47,10 +47,10 @@ def team_info():
return output


def important_dates(date):
def important_dates(year):
"""Returns a dictionary of important dates"""
output = {}
data = mlbgame.data.get_important_dates(date)
data = mlbgame.data.get_important_dates(year)
important_dates = etree.parse(data).getroot().find('queryResults').find('row')
try:
for x in important_dates.attrib: