kobot 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/README.md +7 -5
- data/exe/kobot +10 -1
- data/lib/kobot.rb +1 -0
- data/lib/kobot/config.rb +2 -1
- data/lib/kobot/engine.rb +30 -6
- data/lib/kobot/option.rb +17 -6
- data/lib/kobot/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c867dcb791e15db7a407fc9dc0898ad49e9dccba53514f98ad32b253f1fc8adc
|
4
|
+
data.tar.gz: 6887ebe669b7628a7972a89d2b508b498f5ce856fe80d98e85a52c3bcedfd377
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8ed4028a1a25f75cfa21370c41b72a7fbe66916c442279f7985b3dc6f1be6e540395b81292931549b53496b7db026ec0ca33f9c743623176207d31bf1b740aa4
|
7
|
+
data.tar.gz: b53a002259ad6312ae6437d11320b9b12f8d62e3ac26a01ed4e3dc48399cfb9d2f572384aebc2c3930014bf77e83c6351c7e7cf051b5eab02a87db33e31f7f51
|
data/CHANGELOG.md
CHANGED
@@ -5,3 +5,7 @@
|
|
5
5
|
- Deprecated lower-case environment variables for credentials configuration
|
6
6
|
- Updated option help doc to indicate weekends and public holidays are skipped by default
|
7
7
|
- Updated required_ruby_version to be >= 2.4.0 to align with the webdrivers dependency
|
8
|
+
|
9
|
+
### v1.2.0
|
10
|
+
- Added an option to allow forcibly running regardless of weekends or public holidays
|
11
|
+
- Added an ENV flag to allow requiring lib in local workspace for development purpose
|
data/README.md
CHANGED
@@ -57,15 +57,17 @@ Get help doc:
|
|
57
57
|
```
|
58
58
|
$ kobot -h
|
59
59
|
Usage: kobot [options]
|
60
|
-
-c, --clock CLOCK
|
61
|
-
-l, --loglevel [LEVEL] Specify log level: debug, info, warn, error
|
60
|
+
-c, --clock CLOCK Required; the clock action option: in, out
|
61
|
+
-l, --loglevel [LEVEL] Specify log level: debug, info, warn, error; default is info
|
62
62
|
-s, --skip [D1,D2,D3] Specify dates to skip clock in/out with date format YYYY-MM-DD and
|
63
|
-
multiple values separated by comma, such as: 2020-05-01,2020-12-31
|
64
|
-
|
65
|
-
-t, --to [TO] Email address to send notification to
|
63
|
+
multiple values separated by comma, such as: 2020-05-01,2020-12-31;
|
64
|
+
weekends and public holidays in Japan will be skipped by default
|
65
|
+
-t, --to [TO] Email address to send notification to; by default it is sent to
|
66
66
|
the same self email account used in SMTP config as the sender
|
67
67
|
-n, --notify Enable email notification
|
68
68
|
-d, --dryrun Run the process without actual clock in/out
|
69
|
+
-f, --force Run the process forcibly regardless of weekends or public holidays;
|
70
|
+
must be used together with --dryrun to prevent mistaken operations
|
69
71
|
-x, --headless Start browser in headless mode
|
70
72
|
-g, --geolocation Allow browser to use geolocation
|
71
73
|
-h, --help Show this help message
|
data/exe/kobot
CHANGED
@@ -1,6 +1,15 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
|
4
|
+
begin
|
5
|
+
# For quickly tryout in local development
|
6
|
+
# without installing to system gems path
|
7
|
+
raise LoadError if ENV['KOBOT_DEV']
|
8
|
+
|
9
|
+
require 'kobot'
|
10
|
+
rescue LoadError
|
11
|
+
$LOAD_PATH.unshift File.expand_path('../lib', __dir__)
|
12
|
+
require 'kobot'
|
13
|
+
end
|
5
14
|
|
6
15
|
Kobot.run
|
data/lib/kobot.rb
CHANGED
@@ -33,6 +33,7 @@ module Kobot
|
|
33
33
|
config.clock = options[:clock].to_sym
|
34
34
|
config.loglevel = options[:loglevel]&.to_sym || :info
|
35
35
|
config.dryrun = options[:dryrun]
|
36
|
+
config.force = options[:force]
|
36
37
|
config.skip = options[:skip] || []
|
37
38
|
|
38
39
|
config.kot_url = 'https://s2.kingtime.jp/independent/recorder/personal/'
|
data/lib/kobot/config.rb
CHANGED
data/lib/kobot/engine.rb
CHANGED
@@ -26,11 +26,15 @@ module Kobot
|
|
26
26
|
# to be popped up and should be handled by the outside caller.
|
27
27
|
def start
|
28
28
|
if weekend?
|
29
|
-
|
30
|
-
|
29
|
+
if Config.force
|
30
|
+
Kobot.logger.info("[Force] should have exited: today=#{@today} is weekend")
|
31
|
+
else
|
32
|
+
Kobot.logger.info("Today=#{@today} is weekend")
|
33
|
+
return
|
34
|
+
end
|
31
35
|
end
|
32
36
|
if holiday?
|
33
|
-
Kobot.logger.info("Today=#{@today} is holiday
|
37
|
+
Kobot.logger.info("Today=#{@today} is holiday")
|
34
38
|
return
|
35
39
|
end
|
36
40
|
unless %i[in out].include? Config.clock
|
@@ -147,9 +151,29 @@ module Kobot
|
|
147
151
|
end
|
148
152
|
|
149
153
|
def verify_today_record!
|
150
|
-
raise KotRecordError, "Today=#{@today} is not found on kot
|
151
|
-
|
152
|
-
|
154
|
+
raise KotRecordError, "Today=#{@today} is not found on kot" if @kot_today.strip.empty?
|
155
|
+
|
156
|
+
if kot_weekend?
|
157
|
+
unless Config.force
|
158
|
+
raise KotRecordError,
|
159
|
+
"Today=#{@today} is marked as weekend on kot: #{@kot_today}"
|
160
|
+
end
|
161
|
+
|
162
|
+
Kobot.logger.info(
|
163
|
+
"[Force] should have exited: today=#{@today} is marked as weekend on kot: #{@kot_today}"
|
164
|
+
)
|
165
|
+
end
|
166
|
+
|
167
|
+
if kot_public_holiday?
|
168
|
+
unless Config.force
|
169
|
+
raise KotRecordError,
|
170
|
+
"Today=#{@today} is marked as public holiday on kot: #{@kot_today}"
|
171
|
+
end
|
172
|
+
|
173
|
+
Kobot.logger.info(
|
174
|
+
"[Force] should have exited: today=#{@today} is marked as public holiday on kot: #{@kot_today}"
|
175
|
+
)
|
176
|
+
end
|
153
177
|
end
|
154
178
|
|
155
179
|
def clock_in!
|
data/lib/kobot/option.rb
CHANGED
@@ -14,23 +14,23 @@ module Kobot
|
|
14
14
|
opt_parser = OptionParser.new do |opt|
|
15
15
|
opt.banner = "Usage: #{$PROGRAM_NAME} [options]"
|
16
16
|
|
17
|
-
opt.on('-c', '--clock CLOCK', '
|
17
|
+
opt.on('-c', '--clock CLOCK', 'Required; the clock action option: in, out') do |clock|
|
18
18
|
options[:clock] = clock
|
19
19
|
end
|
20
20
|
|
21
|
-
opt.on('-l', '--loglevel [LEVEL]', 'Specify log level: debug, info, warn, error
|
21
|
+
opt.on('-l', '--loglevel [LEVEL]', 'Specify log level: debug, info, warn, error; default is info') do |level|
|
22
22
|
options[:loglevel] = level
|
23
23
|
end
|
24
24
|
|
25
25
|
opt.on('-s', '--skip [D1,D2,D3]', Array,
|
26
26
|
'Specify dates to skip clock in/out with date format YYYY-MM-DD and',
|
27
|
-
'multiple values separated by comma, such as: 2020-05-01,2020-12-31',
|
28
|
-
'
|
27
|
+
'multiple values separated by comma, such as: 2020-05-01,2020-12-31;',
|
28
|
+
'weekends and public holidays in Japan will be skipped by default') do |skip|
|
29
29
|
options[:skip] = skip
|
30
30
|
end
|
31
31
|
|
32
32
|
opt.on('-t', '--to [TO]',
|
33
|
-
'Email address to send notification to
|
33
|
+
'Email address to send notification to; by default it is sent to',
|
34
34
|
'the same self email account used in SMTP config as the sender') do |to|
|
35
35
|
options[:to] = to
|
36
36
|
end
|
@@ -43,6 +43,12 @@ module Kobot
|
|
43
43
|
options[:dryrun] = dryrun
|
44
44
|
end
|
45
45
|
|
46
|
+
opt.on('-f', '--force',
|
47
|
+
'Run the process forcibly regardless of weekends or public holidays;',
|
48
|
+
'must be used together with --dryrun to prevent mistaken operations') do |force|
|
49
|
+
options[:force] = force
|
50
|
+
end
|
51
|
+
|
46
52
|
opt.on('-x', '--headless', 'Start browser in headless mode') do |headless|
|
47
53
|
options[:headless] = headless
|
48
54
|
end
|
@@ -63,7 +69,12 @@ module Kobot
|
|
63
69
|
end
|
64
70
|
opt_parser.parse! ARGV
|
65
71
|
raise OptionParser::MissingArgument, 'The clock option is required' if options[:clock].nil?
|
66
|
-
|
72
|
+
unless %w[in out].include? options[:clock]
|
73
|
+
raise OptionParser::InvalidArgument, 'The clock option must be either: in, out'
|
74
|
+
end
|
75
|
+
if options[:force] && !options[:dryrun]
|
76
|
+
raise OptionParser::InvalidArgument, 'Must specify --dryrun for forcibly running'
|
77
|
+
end
|
67
78
|
|
68
79
|
options
|
69
80
|
rescue OptionParser::MissingArgument, OptionParser::InvalidArgument => e
|
data/lib/kobot/version.rb
CHANGED