attendance_bot 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 42c93843f97f1f4adce7f3f00c5b2e5ae12bf0f305ba6c34c4b34f1e1efb5917
4
- data.tar.gz: 57261cea7a24c6928ba5432714e9c7f71191f6c8a80601fa965f7bd031f2ddfa
3
+ metadata.gz: e1cc076ced50abb91e311dcf1b4d4fdc0dd840f4b7f2b5f443aaeea8bd519284
4
+ data.tar.gz: 27cc8a9999e54fdf7c16356d4fe839e17117890d386debd3b224ffdf2e517c0d
5
5
  SHA512:
6
- metadata.gz: 80897f9574e16724a186a0fb76d8218c3b7f6238570df670ab7e704e48a8692493fa678d75172762e12d6fe5e9586c861b7bdd7725016c15f74427d38e40fa7e
7
- data.tar.gz: 76bdd4acf5b8bac17bbba424876aad3a4204ab97e99b58b7e2297a685254fbca1466f96c52303a859cedc205ab7652a0941a454323336720006a854bf6a18f81
6
+ metadata.gz: c97844ae3d3ba71ec0f2ba772be0e959bcef38f0dd9e8ff70ef932147ebf7046e9b255916125028b44ebd13733042403a72de9983d4537edbd68e74ed44005df
7
+ data.tar.gz: fad6cb3bc850b41670e441f4969b5dae07edfc0e7176906ea97ae6312f7dd8097463410dae6075015a7ed2ee2f4f5902d710c4b7ab74a4bb91740ad443a4ffdc
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- attendance_bot (0.1.0)
4
+ attendance_bot (0.2.0)
5
5
  config
6
6
  mechanize (~> 2.7, >= 2.7.5)
7
7
  thor
data/exe/attendance_bot CHANGED
@@ -1,3 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
+ require 'bundler/setup'
2
3
  require 'attendance_bot/cli'
3
4
  AttendanceBot::CLI.start
@@ -8,10 +8,16 @@ require 'config'
8
8
 
9
9
  module AttendanceBot
10
10
  class Error < StandardError; end
11
- # Your code goes here...
11
+
12
12
  class Bot
13
- def self.checkin
14
- agent = Mechanize.new
13
+ attr_accessor :agent
14
+
15
+ def initialize
16
+ @agent = Mechanize.new
17
+ Config.load_and_set_settings('./config/config.yml')
18
+ end
19
+
20
+ def login
15
21
  page = agent.get('https://attendance.moneyforward.com/employee_session/new')
16
22
  login_form = page.form(action: '/employee_session')
17
23
 
@@ -19,21 +25,29 @@ module AttendanceBot
19
25
  email_field = login_form.fields.find { |f| f.name == 'employee_session_form[account_name_or_email]' }
20
26
  password_field = login_form.fields.find { |f| f.name == 'employee_session_form[password]' }
21
27
 
22
- Config.load_and_set_settings('./config/config.yml')
23
-
24
28
  office_field.value = Settings.office
25
29
  email_field.value = Settings.email
26
30
  password_field.value = Settings.password
27
31
 
32
+ login_form.submit
33
+ end
28
34
 
29
- page = agent.submit(login_form)
30
-
31
-
35
+ def checkin
36
+ page = login
32
37
  clock_in_form = page.forms.first
33
- user_time = clock_in_form.fields.find{ |f| f.name == 'web_time_recorder_form[user_time]' }
38
+ user_time = clock_in_form.fields.find { |f| f.name == 'web_time_recorder_form[user_time]' }
34
39
  user_time.value = Time.now.to_s
35
40
 
36
41
  clock_in_form.submit
37
42
  end
43
+
44
+ def checkout
45
+ page = login
46
+ clock_out_form = page.forms[1]
47
+ user_time = clock_out_form.fields.find { |f| f.name == 'web_time_recorder_form[user_time]' }
48
+ user_time.value = Time.now.to_s
49
+
50
+ clock_out_form.submit
51
+ end
38
52
  end
39
53
  end
@@ -4,9 +4,19 @@ require 'attendance_bot'
4
4
 
5
5
  module AttendanceBot
6
6
  class CLI < Thor
7
+ def initialize(args = nil, options = nil, config = nil)
8
+ @bot = AttendanceBot::Bot.new
9
+ super
10
+ end
11
+
7
12
  desc 'checkin', 'checkin with current time'
8
13
  def checkin
9
- AttendanceBot::Bot.checkin
14
+ @bot.checkin
15
+ end
16
+
17
+ desc 'checkout', 'checkout with current time'
18
+ def checkout
19
+ @bot.checkout
10
20
  end
11
21
  end
12
22
  end
@@ -1,3 +1,3 @@
1
1
  module AttendanceBot
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: attendance_bot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - LongDT