vgcal 0.2.3 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +10 -8
- data/lib/vgcal/handlers/describer.rb +63 -23
- data/lib/vgcal/my_calendar.rb +11 -21
- data/lib/vgcal/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a632e5cfab5b38c6448d2ec560cbe8b7f81bfa60eaa7926a1cc007946f6d1ab0
|
4
|
+
data.tar.gz: b558eee546de6744e98dd62828d0708c98b6d1bba1b209d8e0885fdb1b05e571
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a5a8d0dd3424094faafd0c3f70a009f2ec95cdfbdb54773ca4da29dae27fcdaa942e3d31de0d5ebc9aa23c3b424dbf5bc8beb3847db8ecf3b41867c5e1d0a107
|
7
|
+
data.tar.gz: 4151ee42551a148d35e6230c99e466ba000778ca60aa4871c1e932664519785fc5b8466febe7afa1709724ce96dcac9af41db4484b07822a1e3baff15ce836c6
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
vgcal (0.
|
4
|
+
vgcal (0.3.1)
|
5
5
|
dotenv
|
6
6
|
google-api-client
|
7
7
|
thor (~> 1.1)
|
@@ -9,7 +9,7 @@ PATH
|
|
9
9
|
GEM
|
10
10
|
remote: https://rubygems.org/
|
11
11
|
specs:
|
12
|
-
activesupport (6.1.4)
|
12
|
+
activesupport (6.1.4.1)
|
13
13
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
14
14
|
i18n (>= 1.6, < 2)
|
15
15
|
minitest (>= 5.1)
|
@@ -22,7 +22,7 @@ GEM
|
|
22
22
|
declarative (0.0.20)
|
23
23
|
diff-lcs (1.4.4)
|
24
24
|
dotenv (2.7.6)
|
25
|
-
faraday (1.
|
25
|
+
faraday (1.7.1)
|
26
26
|
faraday-em_http (~> 1.0)
|
27
27
|
faraday-em_synchrony (~> 1.0)
|
28
28
|
faraday-excon (~> 1.1)
|
@@ -30,6 +30,7 @@ GEM
|
|
30
30
|
faraday-net_http (~> 1.0)
|
31
31
|
faraday-net_http_persistent (~> 1.1)
|
32
32
|
faraday-patron (~> 1.0)
|
33
|
+
faraday-rack (~> 1.0)
|
33
34
|
multipart-post (>= 1.2, < 3)
|
34
35
|
ruby2_keywords (>= 0.0.4)
|
35
36
|
faraday-em_http (1.0.0)
|
@@ -39,6 +40,7 @@ GEM
|
|
39
40
|
faraday-net_http (1.0.1)
|
40
41
|
faraday-net_http_persistent (1.2.0)
|
41
42
|
faraday-patron (1.0.0)
|
43
|
+
faraday-rack (1.0.0)
|
42
44
|
gems (1.2.0)
|
43
45
|
google-api-client (0.53.0)
|
44
46
|
google-apis-core (~> 0.1)
|
@@ -60,19 +62,19 @@ GEM
|
|
60
62
|
google-apis-core (>= 0.4, < 2.a)
|
61
63
|
google-apis-discovery_v1 (~> 0.5)
|
62
64
|
thor (>= 0.20, < 2.a)
|
63
|
-
googleauth (0.
|
65
|
+
googleauth (0.17.1)
|
64
66
|
faraday (>= 0.17.3, < 2.0)
|
65
67
|
jwt (>= 1.4, < 3.0)
|
66
68
|
memoist (~> 0.16)
|
67
69
|
multi_json (~> 1.11)
|
68
70
|
os (>= 0.9, < 2.0)
|
69
|
-
signet (~> 0.
|
71
|
+
signet (~> 0.15)
|
70
72
|
httpclient (2.8.3)
|
71
73
|
i18n (1.8.10)
|
72
74
|
concurrent-ruby (~> 1.0)
|
73
75
|
jwt (2.2.3)
|
74
76
|
memoist (0.16.2)
|
75
|
-
mini_mime (1.1.
|
77
|
+
mini_mime (1.1.1)
|
76
78
|
minitest (5.14.4)
|
77
79
|
multi_json (1.15.0)
|
78
80
|
multipart-post (2.1.1)
|
@@ -116,8 +118,8 @@ GEM
|
|
116
118
|
parser (>= 3.0.1.1)
|
117
119
|
ruby-progressbar (1.11.0)
|
118
120
|
ruby2_keywords (0.0.5)
|
119
|
-
signet (0.
|
120
|
-
addressable (~> 2.
|
121
|
+
signet (0.16.0)
|
122
|
+
addressable (~> 2.8)
|
121
123
|
faraday (>= 0.17.3, < 2.0)
|
122
124
|
jwt (>= 1.5, < 3.0)
|
123
125
|
multi_json (~> 1.10)
|
@@ -3,6 +3,7 @@
|
|
3
3
|
require 'thor'
|
4
4
|
require 'vgcal/my_calendar'
|
5
5
|
require 'fileutils'
|
6
|
+
require 'json'
|
6
7
|
|
7
8
|
module Vgcal
|
8
9
|
module Handlers
|
@@ -13,7 +14,7 @@ module Vgcal
|
|
13
14
|
def init
|
14
15
|
vgcal_dir = "#{Dir.home}/.vgcal"
|
15
16
|
cred_json = "#{vgcal_dir}/credentials.json"
|
16
|
-
dot_env
|
17
|
+
dot_env = "#{vgcal_dir}/.env"
|
17
18
|
Dir.mkdir(vgcal_dir, 0o755) unless Dir.exist?(vgcal_dir)
|
18
19
|
FileUtils.cp('template-credentials.json', cred_json) unless File.exist?(cred_json)
|
19
20
|
FileUtils.cp('template.env', dot_env) unless File.exist?(dot_env)
|
@@ -25,28 +26,22 @@ module Vgcal
|
|
25
26
|
option :'next-week', type: :boolean, aliases: '-n', desc: 'Show next week tasks'
|
26
27
|
option :'start-date', type: :numeric, aliases: '-s', desc: 'Start date. ex.20210701'
|
27
28
|
option :'end-date', type: :numeric, aliases: '-e', desc: 'End date. ex.20210728'
|
29
|
+
option :'output', type: :string, aliases: '-o', desc: 'Output format. [text|json]'
|
28
30
|
|
29
31
|
desc 'show', 'Show google calendar'
|
30
32
|
|
31
33
|
def show
|
32
34
|
Dotenv.load("#{Dir.home}/.vgcal/.env")
|
33
|
-
|
34
|
-
puts
|
35
|
-
mcal = MyCalendar.new(start_date, end_date)
|
35
|
+
mcal = MyCalendar.new(start_date, end_date)
|
36
36
|
events = mcal.events
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
end
|
46
|
-
meetings = mcal.invited_meetings(events)
|
47
|
-
puts "Invited meetings: #{meetings[0]}h(#{(meetings[0] / 8).round(2)}day)"
|
48
|
-
meetings[1].each do |meeting|
|
49
|
-
puts " ・#{meeting[0]}: #{meeting[1]}h"
|
37
|
+
|
38
|
+
case options[:output]
|
39
|
+
when 'json'
|
40
|
+
stdout_json(mcal.tasks(events), mcal.invited_meetings(events))
|
41
|
+
when 'text'
|
42
|
+
stdout_default(mcal.tasks(events), mcal.invited_meetings(events))
|
43
|
+
else
|
44
|
+
stdout_default(mcal.tasks(events), mcal.invited_meetings(events))
|
50
45
|
end
|
51
46
|
end
|
52
47
|
|
@@ -58,6 +53,55 @@ module Vgcal
|
|
58
53
|
|
59
54
|
private
|
60
55
|
|
56
|
+
def stdout_json(my_tasks, invited_meetings)
|
57
|
+
hash = {
|
58
|
+
'start_date': "#{start_date}",
|
59
|
+
'end_date': "#{end_date}",
|
60
|
+
'tasks': []
|
61
|
+
}
|
62
|
+
my_tasks.each do |task|
|
63
|
+
hash[:tasks].push ({
|
64
|
+
"title": task[0],
|
65
|
+
"time": task[1],
|
66
|
+
"task_type": 'my_task'
|
67
|
+
})
|
68
|
+
end
|
69
|
+
invited_meetings.each do |meeting|
|
70
|
+
hash[:tasks].push ({
|
71
|
+
'title': meeting[0],
|
72
|
+
'time': meeting[1],
|
73
|
+
'task_type': 'invited_meeting'
|
74
|
+
})
|
75
|
+
end
|
76
|
+
puts hash.to_json
|
77
|
+
end
|
78
|
+
|
79
|
+
def stdout_default(my_tasks, invited_meetings)
|
80
|
+
puts "Period: #{start_date} - #{end_date}"
|
81
|
+
puts
|
82
|
+
my_task_time = 0
|
83
|
+
my_tasks.select do |n|
|
84
|
+
my_task_time += n[1]
|
85
|
+
end
|
86
|
+
puts "My tasks: #{my_task_time}h(#{(my_task_time / 8).round(2)}day)"
|
87
|
+
my_tasks.each do |task|
|
88
|
+
if my_tasks.is_a?(String)
|
89
|
+
puts " ・#{task[0]}: #{task[1]}"
|
90
|
+
else
|
91
|
+
puts " ・#{task[0]}: #{task[1]}h"
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
meeting_time = 0
|
96
|
+
invited_meetings.select do |m|
|
97
|
+
meeting_time += m[1]
|
98
|
+
end
|
99
|
+
puts "Invited meetings: #{meeting_time}h(#{(meeting_time / 8).round(2)}day)"
|
100
|
+
invited_meetings.each do |meeting|
|
101
|
+
puts " ・#{meeting[0]}: #{meeting[1]}h"
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
61
105
|
def start_date
|
62
106
|
s_date = if options[:'current-week']
|
63
107
|
if Date.today.sunday?
|
@@ -97,7 +141,7 @@ module Vgcal
|
|
97
141
|
end
|
98
142
|
elsif options[:'next-week']
|
99
143
|
if Date.today.sunday?
|
100
|
-
(Date.today +
|
144
|
+
(Date.today + 13).to_s
|
101
145
|
else
|
102
146
|
(Date.today + 7 + (6 - Date.today.wday)).to_s
|
103
147
|
end
|
@@ -113,11 +157,7 @@ module Vgcal
|
|
113
157
|
elsif options['start-date'] && options['end-date']
|
114
158
|
Date.parse(options['end-date'].to_s)
|
115
159
|
else
|
116
|
-
|
117
|
-
(Date.today + 6).to_s
|
118
|
-
else
|
119
|
-
(Date.today + (6 - Date.today.wday)).to_s
|
120
|
-
end
|
160
|
+
Date.today.to_s
|
121
161
|
end
|
122
162
|
"#{e_date}T23:59:59+09:00"
|
123
163
|
end
|
data/lib/vgcal/my_calendar.rb
CHANGED
@@ -8,24 +8,23 @@ module Vgcal
|
|
8
8
|
class MyCalendar
|
9
9
|
def initialize(start_date, end_date)
|
10
10
|
@start_date = start_date
|
11
|
-
@end_date
|
11
|
+
@end_date = end_date
|
12
12
|
end
|
13
13
|
|
14
14
|
def events
|
15
|
-
service
|
15
|
+
service = Google::Apis::CalendarV3::CalendarService.new
|
16
16
|
service.authorization = Vgcal::Authorizer.new.credentials
|
17
|
-
calendar_id
|
17
|
+
calendar_id = 'primary'
|
18
18
|
service.list_events(calendar_id,
|
19
|
-
max_results:
|
19
|
+
max_results: 100,
|
20
20
|
single_events: true,
|
21
|
-
order_by:
|
22
|
-
time_min:
|
23
|
-
time_max:
|
21
|
+
order_by: 'startTime',
|
22
|
+
time_min: @start_date,
|
23
|
+
time_max: @end_date)
|
24
24
|
end
|
25
25
|
|
26
|
-
# return: [
|
26
|
+
# return: [["daily scrum", 0.25], ["SRE定例", 1.0], ["test", 2.0], ["task2", 1.0]]
|
27
27
|
def tasks(events)
|
28
|
-
total_meeting_times = 0
|
29
28
|
tasks_hash = {}
|
30
29
|
events.items.each do |e|
|
31
30
|
if e.organizer.email.include?(my_email_address) && !e.summary.start_with?(*hide_words)
|
@@ -39,19 +38,14 @@ module Vgcal
|
|
39
38
|
else
|
40
39
|
tasks_hash[e.summary] = task_time
|
41
40
|
end
|
42
|
-
total_meeting_times = 0
|
43
|
-
tasks_hash.each do |h|
|
44
|
-
total_meeting_times += h.to_ary[1] unless h.to_ary[1].is_a?(String)
|
45
|
-
end
|
46
41
|
end
|
47
42
|
end
|
48
43
|
end
|
49
|
-
|
44
|
+
tasks_hash.sort.to_a
|
50
45
|
end
|
51
46
|
|
52
|
-
# return: [
|
47
|
+
# return: [["朝会", 0.5], ["daily scrum", 0.25], ["SRE朝会", 0.5], ["定例", 1.0]]
|
53
48
|
def invited_meetings(events)
|
54
|
-
total_meeting_times = 0
|
55
49
|
tasks_hash = {}
|
56
50
|
events.items.each do |e|
|
57
51
|
next if e.organizer.email.include?(my_email_address) || e.summary.start_with?(*hide_words)
|
@@ -67,13 +61,9 @@ module Vgcal
|
|
67
61
|
else
|
68
62
|
tasks_hash[e.summary] = task_time
|
69
63
|
end
|
70
|
-
total_meeting_times = 0
|
71
|
-
tasks_hash.each do |h|
|
72
|
-
total_meeting_times += h.to_ary[1]
|
73
|
-
end
|
74
64
|
end
|
75
65
|
end
|
76
|
-
|
66
|
+
tasks_hash.sort.to_a
|
77
67
|
end
|
78
68
|
|
79
69
|
private
|
data/lib/vgcal/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vgcal
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shota Ito
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-09-
|
11
|
+
date: 2021-09-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|