Giter Club home page Giter Club logo

myfitnesspal_stats's Introduction

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

myfitnesspal_stats's People

Contributors

bitdeli-chef avatar hgducharme avatar wlaurance avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.