Skip to content

Commit

Permalink
Add boolean completion property
Browse files Browse the repository at this point in the history
- `False` by default
- Checks for span within ‘complete_day` div
    + If class of span is `day_incomplete_message`, return False
    + If class of span is `day_complete_message`, return True
    + Could easily be altered to return `complete` or `incomplete`
- Add completion testing (default False) to current `test_get_day()` and `test_get_day_unit_unaware()` tests
- Add new `completed_diary.html`
- Create new test `test_get_completed_day()` to test for `day_complete_message` in the `completed_diary.html`
  • Loading branch information
samhinshaw committed Nov 8, 2017
1 parent 8736f7f commit 7a3b16f
Show file tree
Hide file tree
Showing 4 changed files with 1,544 additions and 2 deletions.
13 changes: 12 additions & 1 deletion myfitnesspal/client.py
Expand Up @@ -248,6 +248,15 @@ def _get_goals(self, document):

return nutrition

def _get_completion(self, document):
completion_header = document.xpath("//div[@id='complete_day']")[0]
completion_message = completion_header.getchildren()[0]

if "day_incomplete_message" in completion_message.classes:
return(False)
elif "day_complete_message" in completion_message.classes:
return(True)

def _get_meals(self, document):
meals = []
fields = None
Expand Down Expand Up @@ -462,6 +471,7 @@ def get_date(self, *args, **kwargs):

meals = self._get_meals(document)
goals = self._get_goals(document)
complete = self._get_completion(document)

# Since this data requires an additional request, let's just
# allow the day object to run the request if necessary.
Expand All @@ -473,7 +483,8 @@ def get_date(self, *args, **kwargs):
meals=meals,
goals=goals,
notes=notes,
water=water
water=water,
complete=complete
)

return day
Expand Down
7 changes: 6 additions & 1 deletion myfitnesspal/day.py
Expand Up @@ -2,12 +2,13 @@


class Day(MFPBase):
def __init__(self, date, meals=None, goals=None, notes=None, water=None):
def __init__(self, date, meals=None, goals=None, notes=None, water=None, complete=False):
self._date = date
self._meals = meals
self._goals = goals
self._notes = notes
self._water = water
self._complete = complete

def __getitem__(self, value):
for meal in self._meals:
Expand All @@ -25,6 +26,10 @@ def keys(self):
def meals(self):
return self._meals

@property
def complete(self):
return self._complete

@property
def entries(self):
for meal in self._meals:
Expand Down

0 comments on commit 7a3b16f

Please sign in to comment.