myfitnesspal_stats 0.2.2 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a474bdee905c1c3d32159c34be8f2bdebeb89b32
4
- data.tar.gz: 4c9ea993e7b20e3c2068577df995c4e22e07ee23
3
+ metadata.gz: 66ddbff289f059d81ec064e40692a968d4d40673
4
+ data.tar.gz: fc894c035079922d741710fcf9dbfd341afaff63
5
5
  SHA512:
6
- metadata.gz: 46517fec18fda5d8bd9a71bc5ebc125b0eeaa4f84bc53282ca62551f75b87d7ac4e4d9f3c36813eb37ffc399f92ff39bc25a5f9a6e7bd681a0d005ba79ac1875
7
- data.tar.gz: c78e5132e75d6202639c876fbb3900f350f8658bc1a0c7a086f4136bd4cb1935dfc23ef995ac56cc42b77a843952c79d79460f11a507f592cb920c06194dbae8
6
+ metadata.gz: 940b1d0a786aa34214d1def9700d87fedc7877cbb53a3c2dffeb4f2262d40398f49e3de89e519e6dd0a9ae33190d996fb9c33df5ea45de85ab15e5948c4c0822
7
+ data.tar.gz: 4ec088f40903288ec0b3a4999f1efdbe89371c63363d8849263be57bb989f66fe761d6ecc28d8ff4c2611b8ea44e1e564fe7cd6d42609cc8a8f6c7c6440e2309
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # MyfitnesspalStats
2
2
 
3
- TODO: Write a gem description
3
+ Myfitnesspal_Stats is a ruby module that allows you to programmatically access your daily nutritional information from [Myfitnesspal.com](http://www.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.
4
4
 
5
5
  ## Installation
6
6
 
@@ -20,7 +20,49 @@ Or install it yourself as:
20
20
 
21
21
  ## Usage
22
22
 
23
- TODO: Write usage instructions here
23
+ Once installation is complete, you cam start accessing your information by initializing a new web scraper:
24
+
25
+ ```ruby
26
+ # Insert your username and password for Myfitnesspal
27
+ # WARNING: DO NOT HARDCODE THIS INTO YOUR SCRIPT IF IT IS A PUBLIC SCRIPT. FUTURE REVISIONS WILL MAKE SURE TO SOLVE THIS PROBLEM.
28
+ scraper = Scraper.new('username', 'password')
29
+ ```
30
+
31
+ To access a specified date and the nutritional information for that day, fetch a specified date and call the `nutrition_totals` method on that day.
32
+
33
+ ```ruby
34
+ # The year, month, and day should all be numbers. Although a string will still work
35
+ scraper.get_date(year, month, day)
36
+
37
+ # Numbers do not have to be padded with zeros, it can be 01 or just 1.
38
+ day = scraper.get_date(2015, 01, 15)
39
+ # ==> #<Day:<object id>
40
+
41
+ # Note: The nutrients that are returned depend on which nutrients you specified to track in your Myfitnesspal settings.
42
+ # The returned hash is formatted like so:
43
+ # :<nutrient> => [how much you ate, your goal, the difference between the two].
44
+ pp day.nutrition_totals
45
+ # ==>
46
+ {:Date=>"Thursday, 15 January 2015",
47
+ :Calories=>[2, 2, -9],
48
+ :Fat=>[49, 50, 1],
49
+ :Carbs=>[296, 290, -6],
50
+ :Fiber=>[45, 35, -10],
51
+ :Protein=>[197, 195, -2],
52
+ :"Potass."=>[2, 4, 1]}
53
+ ```
54
+
55
+
56
+ <!--
57
+ days = Hash.new
58
+ (1..21).each do |day|
59
+ nutrition = scraper.get_date(2015, 02, day).nutrition_totals
60
+ date = Date.new(2015, 02, day).strftime("%a, %e %b")
61
+ days["#{date}"] = nutrition
62
+ end
63
+
64
+ days.each { |number, nutrition_hash| pp nutrition_hash }
65
+ -->
24
66
 
25
67
  ## Contributing
26
68
 
@@ -29,3 +71,7 @@ TODO: Write usage instructions here
29
71
  3. Commit your changes (`git commit -am 'Add some feature'`)
30
72
  4. Push to the branch (`git push origin my-new-feature`)
31
73
  5. Create a new Pull Request
74
+
75
+
76
+ [![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/hgducharme/myfitnesspal_stats/trend.png)](https://bitdeli.com/free "Bitdeli Badge")
77
+
@@ -22,24 +22,27 @@ class Day
22
22
  /(?<=[a-z])(?=[A-Z])/).to_a
23
23
 
24
24
  nutrient_totals = Hash.new
25
- nutrient_totals["Date"] = @date.strftime("%A, %B %e, %Y")
25
+ nutrient_totals[:Date] = @date.strftime("%A, %e %B %Y")
26
26
 
27
27
  # Go through the nutrients table, find the values for its respective column
28
28
  nutrients.each_with_index do |nutrient, index|
29
- todays_total = totals_table.search('td')[index+1].text.strip
30
- daily_goal = totals_table.search('td')[index+9].text.strip
31
- remaining = totals_table.search('td')[index+17].text.strip
29
+ todays_total = totals_table.search('td')[index+1].text.strip.to_i
30
+ daily_goal = totals_table.search('td')[index+9].text.strip.to_i
31
+ difference = totals_table.search('td')[index+17].text.strip.to_i
32
32
 
33
- nutrient_totals[nutrient] = todays_total, daily_goal, remaining
33
+ nutrient_totals[nutrient.to_sym] = todays_total, daily_goal, difference
34
34
  end
35
35
 
36
36
  nutrient_totals
37
37
  end # ---- nutrition_totals
38
38
 
39
+ =begin
39
40
  # WIP
40
41
  def weight
41
42
  reports = @web_crawler.get("#{@login_page}/reports/")
42
43
  weight_report = reports.search('//optgroup')[0].children[0]
43
44
  @web_crawler.click(weight_report)
44
45
  end
46
+ =end
47
+
45
48
  end # ---- class Day
@@ -1,3 +1,3 @@
1
1
  module MyfitnesspalStats
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.4"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: myfitnesspal_stats
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hunter Ducharme
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-14 00:00:00.000000000 Z
11
+ date: 2015-02-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mechanize