Skip to content

Commit

Permalink
Updating changelog; minor cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
coddingtonbear committed Sep 17, 2018
1 parent a44d1e8 commit 8ebe7f8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 77 deletions.
16 changes: 16 additions & 0 deletions changelog.markdown
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
# 1.12 (2018-09-16)

* Adds support for accessing exercise information via the '.exercise' property. Thanks @cathyyul!
* Adds functionality allowing one to set measurements; thanks @rbelzile!
* Adds 'completion' property to indicate whether an entry was marked completed. Thanks @samhinshaw!
* Fixes support for fetching exercise names from public profiles. Thanks again, @samhinshaw!
* Fixes a bug introduced by MFP UI changes causing get_goals to stop working properly. Thanks for the fix, @zagi!
* Fixes a bug that would cause loading data to fail if no completion div existed. Thanks @datamachine!
* Fixes a bug that caused 'n/a' appearing in a column to cause data to be unfetchable. Thanks @jgissend10!

Note that version 1.11 does not exist; I'm just not very good at using a computer.

# 1.10 (2017-08-29)

* Adds support for fetching exercise information. Thanks @samhinshaw!

# 1.9 (2017-06-15)

* Adds support for fetching `unit`, `quantity`, and `short_name` for entries.
Expand Down
79 changes: 2 additions & 77 deletions myfitnesspal/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,11 +353,9 @@ def _get_exercise(self, document):
field.text
)
)
# comment
row = ex_header.findall('tbody')[0].findall('tr')[0]
entries = []
while True:
# comment
if not row.attrib.get('class') is None:
break
columns = row.findall('td')
Expand Down Expand Up @@ -418,7 +416,6 @@ def _get_exercise(self, document):
attrs,
)
)
# comment
row = row.getnext()

exercises.append(
Expand All @@ -430,7 +427,7 @@ def _get_exercise(self, document):

return exercises

def get_exercise(self, *args, **kwargs):
def _get_exercises(self, *args, **kwargs):
if len(args) == 3:
date = datetime.date(
int(args[0]),
Expand All @@ -447,7 +444,6 @@ def get_exercise(self, *args, **kwargs):
)

# get the exercise URL

document = self._get_document_for_url(
self._get_url_for_exercise(
date,
Expand Down Expand Up @@ -498,7 +494,7 @@ def get_date(self, *args, **kwargs):
# allow the day object to run the request if necessary.
notes = lambda: self._get_notes(date)
water = lambda: self._get_water(date)
exercises = lambda: self.get_exercises(date)
exercises = lambda: self._get_exercises(date)


day = Day(
Expand Down Expand Up @@ -577,77 +573,6 @@ def get_measurements(

return measurements

def get_exercises(self, *args, **kwargs):
if len(args) == 3:
date = datetime.date(
int(args[0]),
int(args[1]),
int(args[2]),
)
elif len(args) == 1 and isinstance(args[0], datetime.date):
date = args[0]
else:
raise ValueError(
'get_exercise accepts either a single datetime or'
'date instance, or three integers representing year,'
'month, and day respectively.'
)
document = self._get_document_for_url(
self._get_url_for_exercise(
date,
kwargs.get('username', self.effective_username)
)
)

exercises = self._get_exercises(document)
return exercises
#
# def _get_url_for_exercise(self, date, username):
# return parse.urljoin(
# self.BASE_URL,
# 'exercise/diary/' + username
# ) + '?date=%s' % (
# date.strftime('%Y-%m-%d')
# )

def _get_exercise_fields(self, document):
meal_header = document.xpath("//tr")[0]
tds = meal_header.findall('td')
fields = ['name']
for field in tds[1:]:
fields.append(
self._get_full_name(
field.text
)
)
return fields

def _get_exercises(self, document):
fields = self._get_exercise_fields(document)

exercise_table = document.xpath("//tbody")[0]
trs = exercise_table.findall('tr')
exercises = []
for tr in trs:
tds = tr.findall('td')
found_ex = tds[0].findall("div[@class='exercise-description']/a")
if found_ex:
exercise = {}
ex_name = fields[0]
exercise_description = found_ex[0]
exercise[ex_name] = exercise_description.text.strip()
for n in range(1, len(tds)):
td = tds[n]
try:
ex_name = fields[n]
except IndexError:
# This is the 'delete' button
continue
value = self._extract_value(td)
exercise[ex_name] = self._get_measurement(ex_name, value)
exercises.append(exercise)
return exercises

def set_measurements(
self, measurement='Weight', value=None
):
Expand Down

0 comments on commit 8ebe7f8

Please sign in to comment.