6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/karaage_posting/fitbit_karaage_cli.rb', line 6
def posting(date=Date.today.to_s)
karaage_poster = KaraagePosting::FitbitKaraagePosting.new
authorize_url = karaage_poster.get_fitbit_authorize_uri
puts '#################################'
puts '#################################'
puts "Yes, My life is Karaage eating..."
puts '#################################'
puts '#################################'
puts ''
agent = Mechanize.new
page = agent.get(authorize_url)
form = page.form_with('login')
print "Enter your fitbit email address: "
email = $stdin.gets.chomp
print "Enter your fitbit password: "
system 'stty -echo'
password = $stdin.gets.chomp
system 'stty echo'
puts ""
form.field_with(name: 'email').value = email
form.field_with(name: 'password').value = password
authed_page = form.click_button
if %r%^#{ENV['FITBIT_REDIRECT_URL']}% =~ authed_page.uri.to_s then
redirect_page = authed_page
else
redirect_page = authed_page.form.click_button(authed_page.form.button_with(value: 'Allow'))
end
code = redirect_page.uri.query.split('=')[1]
karaage_poster.get_fitbit_token(code)
puts ''
puts "/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_"
puts "Date #{date}: number of karaage you eat!: #{karaage_poster.get_karaage_count(date)}"
puts "/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_"
puts ''
puts "Posting https://karaage.click....."
karaage_poster.posting_number_of_karaage
puts "done!"
end
|