MyFitnessPal weight importer

Update: July 2018

This script is no longer working due to some changes by MyFitnesspal

Source code is available if you want to try and get it working:

http://blog.gjmccarthy.co.uk/myfitnesspal.php

I wrote this php script as MyFitnesspal does not have the functionality available to import a historical list of weight/body fat values.

After looking at the http post values I came up with a script to read a file and post the values to the MFP site.

In order to upload the data you need to provide your MFP credentials, the script then logs onto MFP and creates a drop down options box based on your settings in MFP.

You will then need to provide a text file containing the data and weight (or Body fat, or what ever you want to import)

Format:

dd/mm/yyyy 123.1

The data will also need to be tab delimited with no blank line of the last line of the scipt. The data will then be uploaded to MFP – it took a good few mins to upload about 2 years of my data so just be patient. Not sure if this is a limitation on the MFP side.

One problem I have noticed is that the first and last values uploaded always contain the wrong vlaue. I will need to fix this up but please we aware of this.

The script also does not check if the data already exists – I’m not sure what would happen. Haven’t tested it.

There are bound to be a few bugs in this. Let me know if you find any. I’ve uploaded 4 years of weight values and it seems to have been uploaded successfully.

After the script has finished the uploaded file and cookies are delete. No personal data is stored on the server.

Update: Busy relooking at my code. Seems MFP has changed something and it no longer works šŸ™

23 comments

Skip to comment form

    • Teri on October 14, 2014 at 22:47
    • Reply

    Does your weight importer still work/exist? I’d love to use it, but the link you provided is broken.

    1. Hi Teri,

      Looks like my ssl on my server has died – I will need to fix this asap but you can also access the link here http://blog.gjmccarthy.co.uk/myfitnesspal.php

    • John on October 30, 2014 at 13:46
    • Reply

    Thanks for this. Just thought I would give some feedback on my experiences with using this for MFP.

    The first time I tried it, it just didn’t work but that was my fault for using a space instead of tab on the *.txt. It did give me an error though which correctly told me what to fix.

    My second attempt worked better. It took about 20 seconds to upload the last 9 months of weight measurements. It then gave me an error at the bottom of the page reading:

    “Incorrect date format in text file!”

    There was nothing wrong with my date format i.e. dd/mm/yyyy, so I thought I would check MFP anyway to see what had happened. It had correctly uploaded all measurements from October until mid July, literally exactly half of all the measurements from March – October. The March till early July measurements however, were all the same weight. It did have the correct dates though, apart from July 14th magically appearing by itself (it wasn’t in my text file).
    I didn’t have a problem with the first and last values, they were both correct.

    The only difference I can see between your instructions and what I did, is you only used one decimal point for the lbs. I was converting from kg to lbs, so I ended up using two decimal points for a few of the values and just hoped it would still recognise it. The two decimal points were spread out over all of the data though, not just the March- July portion.

    I decided to manually fix the other half myself and the measurements are now all there.

    Thanks

    1. Thanks for the info – will look into the date and decimal point issue.

  1. Fixed up a few more issues after my server died and had to rebuild. Hopefully working a bit better now.

    • Martin on January 18, 2015 at 18:22
    • Reply

    Hi there

    I have been unable to get this script to work….The date is in the right format and there is one decimal point. I am getting the error message, “invalid file” – it may be a linux/open office issue? Do you have a template file I can use for weight import?

    Many thanks

    1. How big is the file? Also is it a .txt file?

    • Chris S on February 2, 2015 at 06:05
    • Reply

    Just to let you know this worked a treat to import 1 years worth of data

    txt file with just the date and the weights without titles

    dd/m/yyyy 123.4

    • Paul on February 2, 2015 at 23:19
    • Reply

    I can’t make my txt file work! it’s OK with one line but not with more lines
    eg.

    10/05/2008 78.0
    11/05/2008 78.0

    error is Error – ‘78.0 11/05/2008’ is NOT numeric

    …which obviously it isn’t, but it’s not recognising the carriage return between each record. I’ve tried changing to a tab, but then it only imports the first record. The file is created in Excel and saved out as a tab delimited file, subsequently edited in Coda.

    Any ideas?

    1. That’s odd. Not sure why its not working. I should really add some extra checking into the code.
      Was the format?
      dd/mm/yyyy (tab) 78.0

      For some reason it can’t pull out the value of 78.0. Is there a CR after the last 0? (Maybe there is a extra tab in there?

    • Chris S on February 7, 2015 at 05:31
    • Reply

    Change the month format from mm to m thats what worked for me

    10/5/2008 78.0
    11/5/2008 78.0

    • Paul on February 18, 2015 at 23:15
    • Reply

    Thanks, but still no luck I’m afraid, it seems to be completely ignoring the carriage returns. As I said, I can get it to import the first line, but only if I add another tab before the end of line, or before the first value on the second line. Date format seems to work with both m and mm.

    • Paul on February 18, 2015 at 23:36
    • Reply

    Aha! Had to save it a ‘Windows Formatted Text’ instead of tab delimited file in Excel (weird, maybe it’s a mac thing…), but worked like a charm.

    • Just G on June 14, 2015 at 08:23
    • Reply

    A useful script, but could you provide the source. That way I could convert it to pyton or ruby and run it locally instead of entering my credentials to your site.

    • mdp on December 29, 2015 at 16:27
    • Reply

    worked a treat. thank you.;
    for reference, i used this format

    dd/mm/yyyy [tab] 000.0

    you have to use a tab between the yyyy and your weight. I weigh 200+ lbs, so i have 3 zeros before the decimal.

    side note, you can’t have duplicate dates i think.
    i somehow had a few duplicates and it was giving an unknown date error. removed duplicates and worked.

    • Ashok on January 27, 2016 at 16:20
    • Reply

    Hi I am not able to get the upload to work correctly.

    Invalid date format in file. Use d/m/yyyy

    my test file is labled *.txt and data is just 3 lines.

    05/12/2015 191.2
    06/12/2015 191.3
    07/12/2015 191.4

    • Marc on February 13, 2016 at 16:07
    • Reply

    This still work? everything I try i get an invalid file. File is saved as *.txt file. I’m trying to import just 1 line of code which is tabbed and has no end line.

    01/01/2013 209.0

    • Adam on June 2, 2016 at 17:12
    • Reply

    Worked great for me, not a single problem! Thanks for the script.

    • Milan on July 16, 2016 at 08:55
    • Reply

    It seems that script is not working anymore. Upload went smoothly but no data on MFP šŸ™

      • John on July 12, 2018 at 21:13
      • Reply

      same issue here:

      Data:

      25/01/2011 196.8
      25/01/2011 195.3
      24/01/2011 196.5

      Response:

      Uploading Data
      Sending Data….196.8
      Sending Data….195.3
      Sending Data….196.5
      Import complete
      Deleting uploaded file
      Deleting cookies

      Nothing in MFP though šŸ™

    • Ken on April 25, 2017 at 11:28
    • Reply

    Hey Greg, would you consider open-sourcing the php script? It would be awesome to use as a base for personal projects, to hook into my own scripts and such. And beyind tha, not that I don’t trust your intentions, but I do feel weird giving my creds to an unknown server, especially since it’s not over https.

    1. Hi Ken. Good point. I’ll put up the script within the next few days. Its been a while since I’ve used it so maybe someone will be able to tweak and improve it.

    • John on July 12, 2018 at 21:39
    • Reply

    CSV Import app on the app store does the same thing, just tried with success in a very similar format. It is paid mind but at Ā£2 its good value

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.