Skip to content

Commit

Permalink
#112: Updating readme to clarify that returned water is in milliliters.
Browse files Browse the repository at this point in the history
  • Loading branch information
coddingtonbear committed Nov 30, 2021
1 parent b066263 commit ee42951
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
14 changes: 7 additions & 7 deletions myfitnesspal/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import logging
import re
from collections import OrderedDict
from typing import Dict, List, Optional, overload
from typing import Dict, List, Optional, Union, overload

import lxml.html
import requests
Expand Down Expand Up @@ -667,7 +667,7 @@ def _get_notes(self, date: datetime.date) -> Note:
)
return Note(result.json()["item"])

def _get_water(self, date: datetime.date) -> float:
def _get_water(self, date: datetime.date) -> Union[float, Volume]:
result = self._get_request_for_url(
parse.urljoin(
self.BASE_URL_SECURE,
Expand All @@ -676,10 +676,10 @@ def _get_water(self, date: datetime.date) -> float:
+ "?date={date}".format(date=date.strftime("%Y-%m-%d"))
)
value = result.json()["item"]["milliliters"]
cups = int(Volume(ml=value).us_cup)
if not self.unit_aware:
return cups
return Volume(us_cup=cups)
if self.unit_aware:
return Volume(ml=value)

return value

def __str__(self) -> str:
return f"MyFitnessPal Client for {self.effective_username}"
Expand Down Expand Up @@ -797,4 +797,4 @@ def get_food_item_details(self, mfp_id: int) -> FoodItem:
confirmations=details["confirmations"],
serving_sizes=details["serving_sizes"],
client=self,
)
)
2 changes: 1 addition & 1 deletion readme.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ day.totals
# 'sugar': 103}
```

Or, if you just want to see how many cups of water you've recorded, or the notes you've entered for a day:
Or, if you just want to see how many milliliters of water you've recorded, or the notes you've entered for a day:

```python
day.water
Expand Down

0 comments on commit ee42951

Please sign in to comment.