No commit activity in last 3 years
No release in over 3 years
A module that replace Myfitnesspal's API. Get access to all of your stats & attributes for nutrition and weight progression.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.7
~> 10.0
~> 3.2
~> 2.9
~> 1.20

Runtime

~> 2.7
 Project Readme

MyfitnesspalStats

Myfitnesspal_Stats is a ruby module that allows you to programmatically access your daily nutritional information from Myfitnesspal.com. It gives you the ability to access your nutritional totals for a specified date, as well as the break down of each meal & food logged for that day.

Installation

Add this line to your application's Gemfile:

gem 'myfitnesspal_stats'

And then execute:

$ bundle

Or install it yourself as:

$ gem install myfitnesspal_stats

Usage

Getting Started: Once installation of this gem is complete, initialize a new web scraper:

include 'myfitnesspal_stats'

# Insert your username and password for Myfitnesspal
# WARNING: DO NOT HARDCODE THIS INTO YOUR SCRIPT IF IT IS A PUBLIC SCRIPT. FUTURE REVISIONS WILL MAKE SURE TO SOLVE THIS PROBLEM.
scraper = Scraper.new('username', 'password')

Accessing nutritional information: To access nutritional information for a specified date, create a new Day instance and then call the .nutrition_totals on that day:

# The year, month, and day should all be numbers. Although a string will still work
scraper.get_date(year, month, day)

# Numbers do not have to be padded with zeros, it can be 01 or just 1.
day = scraper.get_date(2015, 01, 15)
# ==> #<Day:<object id>

# Note: The nutrients that are returned depend on which nutrients you specified to track in your Myfitnesspal settings.
# The returned hash is formatted like so:
# :<nutrient> => [how much you ate, your goal, the difference between the two].
pp day.nutrition_totals
# ==> 
{:Date=>"Thursday, 15 January 2015",
 :Calories=>["2,399", "2,390", "-9"],
 :Fat=>["49", "50", "1"],
 :Carbs=>["296", "290", "-6"],
 :Fiber=>["45", "35", "-10"],
 :Protein=>["197", "195", "-2"],
 :"Potass."=>["2,476", "4,000", "1,524"]}

How to retrive data from the hash: This is simple ruby practice, but in order to save any frustration I will outline the process here:

day = scraper.get_date(2015, 01, 15)
nutrition_data = day.nutrition_totals

pp nutrition_data[:Date]
pp nutrition_data[:Calories]
pp nutrition_data[:Calories][0]
pp nutrition_data[:Fiber][1]
pp nutrition_data[:Carbs][1, 2]

#### OUTPUT:

# ==> "Thursday, 15 January 2015"
# ==> ["2,399", "2,390", "-9"]
# ==> "2,399"
# ==> "35"
# ==> ["290", "-6"]

Contributing

  1. Fork it ( https://github.com/hgducharme/myfitnesspal_stats/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Bitdeli Badge