Skip to content

Instantly share code, notes, and snippets.

@vtorica
Created June 28, 2017 12:38
Show Gist options
  • Save vtorica/a1304f71468fc4c6750f12f12b96944d to your computer and use it in GitHub Desktop.
Save vtorica/a1304f71468fc4c6750f12f12b96944d to your computer and use it in GitHub Desktop.
eatsmartの日々の記録から摂取カロリーを取得する
require 'mechanize'
require 'date'
class EatSmart
LOGIN_URL = 'https://www.eatsmart.jp/do/login/index'
# 日々の記録 末尾に'YYYYYMMDD/'が必要
DAY_URL = 'https://www.eatsmart.jp/do/esmanote/day/param/ymd/'
def initialize
@agent = Mechanize.new
end
def login(email, password)
page = @agent.get(LOGIN_URL)
mypage = page.form_with(name: 'login.LoginBean') do |form|
form.mailaddress = email
form.password = password
end.submit
mypage.search('title').text.include?('あなたの')
end
def getcal(yyyymmdd)
page = @agent.get(DAY_URL + yyyymmdd + '/')
page.css('html body div#page div#container div#contents div#main div#oneday.contents div.left div#calIn.content div.title02 p.text').text
end
end
easma = EatSmart.new
easma.login('mail@example.com', 'password')
puts easma.getcal(Time.now.strftime('%Y%m%d'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment