coddingtonbear / python-myfitnesspal

Access your meal tracking data stored in MyFitnessPal programatically
MIT License
800 stars 138 forks source link

Solution for water_header IndexError: list index out of range #42

Closed sergekatzmann closed 8 years ago

sergekatzmann commented 8 years ago

Hi coddingtonbear,

I had the same problem as described in the Issue "index out of range #41". A simple check for array length is sufficient to prevent the exception.

Kind regards Serge

coddingtonbear commented 8 years ago

I'm very curious about why this error is occurring at all, though; I don't see it when I try to gather statistics. @sergekatzmann: could you help shed light on the situation by sending me the HTML of of your a Food Diary page on your account matching a date that you receive this exception upon?

sergekatzmann commented 8 years ago

It seems that I don't have any page with the right markup for water for any given date. Could it be some sort of a redesign change on myfitnesspal page? You can see the relevant page part and markup if you look at this screenshot https://abload.de/img/myfipal_waterp1s8t.png The paths xpath is looking for in case of water are not present.

coddingtonbear commented 8 years ago

Awesome, that's very helpful. I think the reason that this isn't blowing up for me is that I don't track that particular metric. I've pushed up some changes (53b3be9f0f0fbfc8062474160509e2c2a930e70d ; released as part of 1.8.4) that I think should make this metric a little more robust.

Could you give it a shot and let me know how much luck you have?

sergekatzmann commented 8 years ago

Unfortunately the solution is not working. The reason for that is that the markup do not have water and notes information anymore. The page is getting data using async ajax call. The result is now in json format. Chrome developer tools show the modified DOM not the original http stream. So that was a dead-end :(

Current example for water:

request: http://www.myfitnesspal.com/food/water?date=2016-09-04

response: {"item":{"date":"2016-09-04","milliliters":2000.0}}

Current example for notes:

request: http://www.myfitnesspal.com/food/note?date=2016-09-04

response: {"item":{"type":"food","date":"2016-09-04","body":"My note"}}

Hope this information is useful

coddingtonbear commented 8 years ago

That is very helpful, @sergekatzmann! I'm fixing things up as we speak such that they gather water/notes data via an XHR.

coddingtonbear commented 8 years ago

OK! This should be fixed now thanks to your help above, @sergekatzmann.

Cheers!