myfitnesspal_stats 0.1.0 → 0.2.0
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 +4 -4
- data/.gitignore +1 -0
- data/Gemfile +0 -1
- data/lib/myfitnesspal_stats/account.rb +6 -6
- data/lib/myfitnesspal_stats/scraper.rb +4 -2
- data/lib/myfitnesspal_stats/version.rb +1 -1
- data/myfitnesspal_stats.gemspec +5 -5
- metadata +20 -20
- data/myfitnesspal_stats-0.0.1.gem +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f61a588a5d049eb4fa6de0372d09e6d8483c8908
|
|
4
|
+
data.tar.gz: cc5318cd057331c6bb5c0e6c2fc44d308f6318b7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f600b1b3dedf6dda633816e3b600b5dd8823816c1cc4b48bd57c1ef8496565094b60c056c7e34e08241c88d464420589ab96077d25fcb5683d1bb995fcb7a541
|
|
7
|
+
data.tar.gz: 6b66aa75576fb73394c1943f348ba7bee09df57c6c5e857a81169079945e91cc630ca3d9c9e4efc811d83a32003466005e0451ae47819cfa615bec9610b2e314
|
data/.gitignore
CHANGED
data/Gemfile
CHANGED
|
@@ -5,23 +5,23 @@ class Account
|
|
|
5
5
|
def initialize(username = nil, password = nil)
|
|
6
6
|
@username = username
|
|
7
7
|
@password = password
|
|
8
|
-
end
|
|
9
8
|
|
|
10
|
-
|
|
11
|
-
web_crawler = Mechanize.new do |web_crawler|
|
|
12
|
-
# MFP refreshes after login
|
|
9
|
+
@web_crawler = Mechanize.new do |web_crawler|
|
|
13
10
|
web_crawler.follow_meta_refresh = true
|
|
14
11
|
end
|
|
12
|
+
end
|
|
15
13
|
|
|
14
|
+
def login
|
|
16
15
|
# Go to homepage, click log in, and submit the form
|
|
17
|
-
home_page = web_crawler.get('http://www.myfitnesspal.com/')
|
|
16
|
+
home_page = @web_crawler.get('http://www.myfitnesspal.com/')
|
|
18
17
|
login_form = home_page.form_with(id: "fancy_login")
|
|
19
18
|
login_form['username'] = @username
|
|
20
19
|
login_form['password'] = @password
|
|
21
20
|
current_page = login_form.submit
|
|
21
|
+
login_cookies = @web_crawler.cookie_jar.save('cookies.yml', session: true)
|
|
22
22
|
|
|
23
23
|
# Checks to see if there was an error when logging in
|
|
24
|
-
|
|
24
|
+
begin
|
|
25
25
|
calories_left = current_page.search('div#calories-remaining-number').text
|
|
26
26
|
puts "#{@username} has successfully logged in!"
|
|
27
27
|
return current_page
|
|
@@ -13,6 +13,7 @@ class Scraper
|
|
|
13
13
|
@login_page = @account.login
|
|
14
14
|
|
|
15
15
|
@web_crawler = Mechanize.new do |web_crawler|
|
|
16
|
+
web_crawler.cookie_jar.load('cookies.yml')
|
|
16
17
|
web_crawler.follow_meta_refresh = true
|
|
17
18
|
end
|
|
18
19
|
end # .initialize
|
|
@@ -20,7 +21,8 @@ class Scraper
|
|
|
20
21
|
def get_nutrition(year = @date.year, month = @date.month, day = @date.day)
|
|
21
22
|
date = Date.new(year, month, day)
|
|
22
23
|
|
|
23
|
-
|
|
24
|
+
# @login_page.uri already has a trailing slash: /
|
|
25
|
+
diary = @web_crawler.get("#{@login_page.uri}food/diary/#{@username}?date=#{date}")
|
|
24
26
|
totals_table = diary.search('tr.total')
|
|
25
27
|
|
|
26
28
|
# Find which nutrients are being tracked, and put them into an array
|
|
@@ -35,7 +37,7 @@ class Scraper
|
|
|
35
37
|
todays_total = totals_table.search('td')[index+1].text.strip
|
|
36
38
|
daily_goal = totals_table.search('td')[index+9].text.strip
|
|
37
39
|
remaining = totals_table.search('td')[index+17].text.strip
|
|
38
|
-
puts "-- #{nutrient}: \n Total: #{todays_total} \n Your goal: #{daily_goal} \n Remaining: #{remaining} \n\n"
|
|
40
|
+
#puts "-- #{nutrient}: \n Total: #{todays_total} \n Your goal: #{daily_goal} \n Remaining: #{remaining} \n\n"
|
|
39
41
|
|
|
40
42
|
nutrient_totals[nutrient] = todays_total, daily_goal, remaining
|
|
41
43
|
end
|
data/myfitnesspal_stats.gemspec
CHANGED
|
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
|
|
|
9
9
|
spec.authors = ["Hunter Ducharme"]
|
|
10
10
|
spec.email = ["hgducharme@gmail.com"]
|
|
11
11
|
spec.summary = %q{Programatically access your daily nutrition from myfitnesspal.}
|
|
12
|
-
spec.description = %q{
|
|
12
|
+
spec.description = %q{A module that replace Myfitnesspal's API. Get access to all of your stats & attributes for nutrition and weight progression.}
|
|
13
13
|
spec.homepage = ""
|
|
14
14
|
spec.license = "MIT"
|
|
15
15
|
|
|
@@ -18,11 +18,11 @@ Gem::Specification.new do |spec|
|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
|
19
19
|
spec.require_paths = ["lib"]
|
|
20
20
|
|
|
21
|
-
spec.add_runtime_dependency "mechanize"
|
|
21
|
+
spec.add_runtime_dependency "mechanize", "~> 2.7"
|
|
22
22
|
|
|
23
23
|
spec.add_development_dependency "bundler", "~> 1.7"
|
|
24
24
|
spec.add_development_dependency "rake", "~> 10.0"
|
|
25
|
-
spec.add_development_dependency "rspec"
|
|
26
|
-
spec.add_development_dependency "webmock"
|
|
27
|
-
spec.add_development_dependency "vcr"
|
|
25
|
+
spec.add_development_dependency "rspec", "~> 3.2"
|
|
26
|
+
spec.add_development_dependency "webmock", "~> 1.20"
|
|
27
|
+
spec.add_development_dependency "vcr", "~> 2.9"
|
|
28
28
|
end
|
metadata
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: myfitnesspal_stats
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
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-
|
|
11
|
+
date: 2015-02-14 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: mechanize
|
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
|
16
16
|
requirements:
|
|
17
|
-
- - "
|
|
17
|
+
- - "~>"
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: '
|
|
19
|
+
version: '2.7'
|
|
20
20
|
type: :runtime
|
|
21
21
|
prerelease: false
|
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
23
|
requirements:
|
|
24
|
-
- - "
|
|
24
|
+
- - "~>"
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
|
-
version: '
|
|
26
|
+
version: '2.7'
|
|
27
27
|
- !ruby/object:Gem::Dependency
|
|
28
28
|
name: bundler
|
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -56,45 +56,46 @@ dependencies:
|
|
|
56
56
|
name: rspec
|
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
|
58
58
|
requirements:
|
|
59
|
-
- - "
|
|
59
|
+
- - "~>"
|
|
60
60
|
- !ruby/object:Gem::Version
|
|
61
|
-
version: '
|
|
61
|
+
version: '3.2'
|
|
62
62
|
type: :development
|
|
63
63
|
prerelease: false
|
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
|
65
65
|
requirements:
|
|
66
|
-
- - "
|
|
66
|
+
- - "~>"
|
|
67
67
|
- !ruby/object:Gem::Version
|
|
68
|
-
version: '
|
|
68
|
+
version: '3.2'
|
|
69
69
|
- !ruby/object:Gem::Dependency
|
|
70
70
|
name: webmock
|
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
|
72
72
|
requirements:
|
|
73
|
-
- - "
|
|
73
|
+
- - "~>"
|
|
74
74
|
- !ruby/object:Gem::Version
|
|
75
|
-
version: '
|
|
75
|
+
version: '1.20'
|
|
76
76
|
type: :development
|
|
77
77
|
prerelease: false
|
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
|
79
79
|
requirements:
|
|
80
|
-
- - "
|
|
80
|
+
- - "~>"
|
|
81
81
|
- !ruby/object:Gem::Version
|
|
82
|
-
version: '
|
|
82
|
+
version: '1.20'
|
|
83
83
|
- !ruby/object:Gem::Dependency
|
|
84
84
|
name: vcr
|
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
|
86
86
|
requirements:
|
|
87
|
-
- - "
|
|
87
|
+
- - "~>"
|
|
88
88
|
- !ruby/object:Gem::Version
|
|
89
|
-
version: '
|
|
89
|
+
version: '2.9'
|
|
90
90
|
type: :development
|
|
91
91
|
prerelease: false
|
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
|
93
93
|
requirements:
|
|
94
|
-
- - "
|
|
94
|
+
- - "~>"
|
|
95
95
|
- !ruby/object:Gem::Version
|
|
96
|
-
version: '
|
|
97
|
-
description:
|
|
96
|
+
version: '2.9'
|
|
97
|
+
description: A module that replace Myfitnesspal's API. Get access to all of your stats
|
|
98
|
+
& attributes for nutrition and weight progression.
|
|
98
99
|
email:
|
|
99
100
|
- hgducharme@gmail.com
|
|
100
101
|
executables: []
|
|
@@ -112,7 +113,6 @@ files:
|
|
|
112
113
|
- lib/myfitnesspal_stats/day.rb
|
|
113
114
|
- lib/myfitnesspal_stats/scraper.rb
|
|
114
115
|
- lib/myfitnesspal_stats/version.rb
|
|
115
|
-
- myfitnesspal_stats-0.0.1.gem
|
|
116
116
|
- myfitnesspal_stats.gemspec
|
|
117
117
|
- spec/account_spec.rb
|
|
118
118
|
- spec/day_spec.rb
|
|
Binary file
|