wger icon indicating copy to clipboard operation
wger copied to clipboard

Add myfitnesspal weight data sync

Open lediable opened this issue 9 years ago • 7 comments

Hi!

Great software. It's possibile in the future to import the weight data from myfitnesspal to wger?

lediable avatar Aug 03 '16 16:08 lediable

Hi there!

Great that you like the software! :D There are already a couple of issues about connecting external services. This is something I think I'll look into after this release. If this is something you could imagine doing yourself, I'll definitely help you.

rolandgeider avatar Aug 03 '16 17:08 rolandgeider

Sure, I can try!

lediable avatar Aug 04 '16 10:08 lediable

Awesome!

rolandgeider avatar Aug 04 '16 11:08 rolandgeider

I've looked around a (very!) little bit. And while myfitnesspal does provide a REST API, it is private access only.

On the other hand, I've found this project that just uses a web scrapper to access the data and provide it in a nice python object that can be just used. Downsides:

  • every time the website changes it can potentially kill this way of getting the data. This might not be such a big problem if such changes don't occur very often and the project reacts fast to them (since it looks actively maintained this is probably the case)
  • security considerations on how to manage the user's password since there's no token or anything, either it has to be entered every time a sync occurs or it is stored in plain text in our db :scream:

rolandgeider avatar Sep 20 '16 22:09 rolandgeider

Yes, I am using python-myfitnesspal in local to control my weight and calorie swing.

I know that mfp can does some changes to break this script but I am using it for 6 months and doesn't have any issue. And yes, at least the project is stille alive and maintained so doesn't seem a big issue.

Yes, the big issue here is how store the passoword. I am not an expert in this field but I know that django can store the passwords trought PBKDF2 or we can use an external lib like passlib.

lediable avatar Sep 25 '16 17:09 lediable

Ah, nice that you are using that library already! As I said, it looks that it would be easy enough to integrate.

The problem with the password is that hashes only work on a local installation. When the user inputs the password, a hash of that value is calculated and compared with the saved value from the database, if they match, it was the same password and the user can login. But we can't do this with myfitnesspal, because we simulate logging in through the website as a regular user and "clicking" on things.

As an alternative to saving the password in plain text in the databae, we could save it in a cookie on the user's computer. It is possible (and easy!) to encrypt this value with a key that is unique for each instance. The advantage is that this would not leave the user's computer (obviously we'd put a checkbox in front of this so it doesn't get used on public PCs) and we would not keep any lists, we could only access this when the user actually visits that specific page and sends the cookie. Just an idea.

rolandgeider avatar Sep 26 '16 14:09 rolandgeider

Well, it seems that you have found the solution :)

I like it. Simple and efficent.

lediable avatar Sep 28 '16 22:09 lediable