attendance_bot 0.2.0 → 0.3.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/Gemfile.lock +3 -1
- data/attendance_bot.gemspec +1 -0
- data/lib/attendance_bot/bot.rb +48 -0
- data/lib/attendance_bot/cli.rb +7 -2
- data/lib/attendance_bot/generator.rb +34 -0
- data/lib/attendance_bot/template_config.yml +4 -0
- data/lib/attendance_bot/version.rb +1 -1
- data/lib/attendance_bot.rb +0 -47
- metadata +24 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cf6e10081dfda398f6abc44fc1769477945f7a7e1dadc37d0eae26051c90a0d3
|
4
|
+
data.tar.gz: 387daa774cd1cf430cfed04812f24c69299b74505f65e073b4ad3d5eb7a15a92
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eab152e6221b372977d78560a960b42f70746c09e6d70d4d17bd67c6627507d2403d75558d2d363f13844a44701138498c29b2c264c835b38e3d7b03fdde2f75
|
7
|
+
data.tar.gz: 167cdbd421e7b27fbb7d7eaa994989106ac94f096e89066ee62e34e0751463255e1a4f35312d5d0f22fe8b5a5453031e6cc16fd1658ed44d8ae040e5b7370acc
|
data/Gemfile.lock
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
attendance_bot (0.
|
4
|
+
attendance_bot (0.3.0)
|
5
5
|
config
|
6
|
+
highline (~> 2.0, >= 2.0.3)
|
6
7
|
mechanize (~> 2.7, >= 2.7.5)
|
7
8
|
thor
|
8
9
|
|
@@ -57,6 +58,7 @@ GEM
|
|
57
58
|
dry-equalizer (~> 0.2)
|
58
59
|
dry-initializer (~> 3.0)
|
59
60
|
dry-schema (~> 1.5)
|
61
|
+
highline (2.0.3)
|
60
62
|
http-cookie (1.0.3)
|
61
63
|
domain_name (~> 0.5)
|
62
64
|
mechanize (2.7.6)
|
data/attendance_bot.gemspec
CHANGED
@@ -34,6 +34,7 @@ Gem::Specification.new do |spec|
|
|
34
34
|
spec.add_development_dependency 'rake', '~> 10.0'
|
35
35
|
|
36
36
|
spec.add_dependency 'config'
|
37
|
+
spec.add_dependency 'highline', '~> 2.0', '>= 2.0.3'
|
37
38
|
spec.add_dependency 'mechanize', '~> 2.7', '>= 2.7.5'
|
38
39
|
spec.add_dependency 'thor'
|
39
40
|
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'mechanize'
|
2
|
+
require 'pry'
|
3
|
+
require 'config'
|
4
|
+
|
5
|
+
module AttendanceBot
|
6
|
+
class Bot
|
7
|
+
attr_accessor :agent
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@agent = Mechanize.new
|
11
|
+
path_to_config = File.dirname(__FILE__) + '/config/config.yml'
|
12
|
+
Config.load_and_set_settings(path_to_config)
|
13
|
+
end
|
14
|
+
|
15
|
+
def login
|
16
|
+
page = agent.get(Settings.login_url)
|
17
|
+
login_form = page.form(action: '/employee_session')
|
18
|
+
|
19
|
+
office_field = login_form.fields.find { |f| f.name == 'employee_session_form[office_account_name]' }
|
20
|
+
email_field = login_form.fields.find { |f| f.name == 'employee_session_form[account_name_or_email]' }
|
21
|
+
password_field = login_form.fields.find { |f| f.name == 'employee_session_form[password]' }
|
22
|
+
|
23
|
+
office_field.value = Settings.office
|
24
|
+
email_field.value = Settings.email
|
25
|
+
password_field.value = Settings.password
|
26
|
+
|
27
|
+
login_form.submit
|
28
|
+
end
|
29
|
+
|
30
|
+
def checkin
|
31
|
+
page = login
|
32
|
+
clock_in_form = page.forms.first
|
33
|
+
user_time = clock_in_form.fields.find { |f| f.name == 'web_time_recorder_form[user_time]' }
|
34
|
+
user_time.value = Time.now.to_s
|
35
|
+
|
36
|
+
clock_in_form.submit
|
37
|
+
end
|
38
|
+
|
39
|
+
def checkout
|
40
|
+
page = login
|
41
|
+
clock_out_form = page.forms[1]
|
42
|
+
user_time = clock_out_form.fields.find { |f| f.name == 'web_time_recorder_form[user_time]' }
|
43
|
+
user_time.value = Time.now.to_s
|
44
|
+
|
45
|
+
clock_out_form.submit
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/lib/attendance_bot/cli.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'thor'
|
2
|
-
require 'attendance_bot'
|
3
|
-
|
2
|
+
require 'attendance_bot/bot'
|
3
|
+
require 'attendance_bot/generator'
|
4
4
|
|
5
5
|
module AttendanceBot
|
6
6
|
class CLI < Thor
|
@@ -18,5 +18,10 @@ module AttendanceBot
|
|
18
18
|
def checkout
|
19
19
|
@bot.checkout
|
20
20
|
end
|
21
|
+
|
22
|
+
desc 'generate', 'Generates a config'
|
23
|
+
def generate
|
24
|
+
AttendanceBot::Generator.start
|
25
|
+
end
|
21
26
|
end
|
22
27
|
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'thor/group'
|
2
|
+
require 'highline'
|
3
|
+
require 'yaml'
|
4
|
+
module AttendanceBot
|
5
|
+
class Generator < Thor::Group
|
6
|
+
include Thor::Actions
|
7
|
+
|
8
|
+
def destination_path
|
9
|
+
self.class.source_root + '/config/config.yml'
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.source_root
|
13
|
+
File.dirname(__FILE__)
|
14
|
+
end
|
15
|
+
|
16
|
+
def create_group
|
17
|
+
empty_directory('config')
|
18
|
+
end
|
19
|
+
|
20
|
+
def copy_config
|
21
|
+
template('template_config.yml', destination_path)
|
22
|
+
end
|
23
|
+
|
24
|
+
def write_config
|
25
|
+
cli = HighLine.new
|
26
|
+
email = cli.ask 'Enter your attendance email: '
|
27
|
+
password = cli.ask('Enter your password: ') { |q| q.echo = 'x' }
|
28
|
+
config_file = YAML::load_file(destination_path)
|
29
|
+
config_file['email'] = email
|
30
|
+
config_file['password'] = password
|
31
|
+
File.open(destination_path, 'w') { |f| f.write config_file.to_yaml }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/attendance_bot.rb
CHANGED
@@ -1,53 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'mechanize'
|
4
|
-
require 'rubygems'
|
5
|
-
require 'pry'
|
6
2
|
require 'attendance_bot/version'
|
7
|
-
require 'config'
|
8
3
|
|
9
4
|
module AttendanceBot
|
10
5
|
class Error < StandardError; end
|
11
|
-
|
12
|
-
class Bot
|
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
|
21
|
-
page = agent.get('https://attendance.moneyforward.com/employee_session/new')
|
22
|
-
login_form = page.form(action: '/employee_session')
|
23
|
-
|
24
|
-
office_field = login_form.fields.find { |f| f.name == 'employee_session_form[office_account_name]' }
|
25
|
-
email_field = login_form.fields.find { |f| f.name == 'employee_session_form[account_name_or_email]' }
|
26
|
-
password_field = login_form.fields.find { |f| f.name == 'employee_session_form[password]' }
|
27
|
-
|
28
|
-
office_field.value = Settings.office
|
29
|
-
email_field.value = Settings.email
|
30
|
-
password_field.value = Settings.password
|
31
|
-
|
32
|
-
login_form.submit
|
33
|
-
end
|
34
|
-
|
35
|
-
def checkin
|
36
|
-
page = login
|
37
|
-
clock_in_form = page.forms.first
|
38
|
-
user_time = clock_in_form.fields.find { |f| f.name == 'web_time_recorder_form[user_time]' }
|
39
|
-
user_time.value = Time.now.to_s
|
40
|
-
|
41
|
-
clock_in_form.submit
|
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
|
52
|
-
end
|
53
6
|
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.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- LongDT
|
@@ -66,6 +66,26 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: highline
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '2.0'
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: 2.0.3
|
79
|
+
type: :runtime
|
80
|
+
prerelease: false
|
81
|
+
version_requirements: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - "~>"
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '2.0'
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: 2.0.3
|
69
89
|
- !ruby/object:Gem::Dependency
|
70
90
|
name: mechanize
|
71
91
|
requirement: !ruby/object:Gem::Requirement
|
@@ -121,7 +141,10 @@ files:
|
|
121
141
|
- bin/setup
|
122
142
|
- exe/attendance_bot
|
123
143
|
- lib/attendance_bot.rb
|
144
|
+
- lib/attendance_bot/bot.rb
|
124
145
|
- lib/attendance_bot/cli.rb
|
146
|
+
- lib/attendance_bot/generator.rb
|
147
|
+
- lib/attendance_bot/template_config.yml
|
125
148
|
- lib/attendance_bot/version.rb
|
126
149
|
homepage: https://github.com/thelong0705/attendance_bot
|
127
150
|
licenses:
|