vgcal 0.2.1 → 0.3.2
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 +10 -8
- data/README.md +32 -7
- data/lib/vgcal/handlers/describer.rb +64 -20
- data/lib/vgcal/my_calendar.rb +12 -22
- 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: ef38649601c8235213557c91a0140fc4b9dbb48321cd8681a52f5a8175b7ad8c
|
|
4
|
+
data.tar.gz: 2858b7e91979460d4528b85592b6be3279f4c44504f64513ca3face8beb77adf
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2945ec5f859fdf234b24c848b0f8a253d09d6b82d07ae7a9be77ccc7129e9ce19d5d2cc9189e11031532704d2562d24dcfd15b7a2a75c44c6e2ab3d9708a724e
|
|
7
|
+
data.tar.gz: d06dd6b8a38199c763096f0b5cf5195455be81cb67af952f6c93d653d8065a2683afbe23760e3b2ec96f1e34dacc7a945cf1b1cd4d1def1a12ba762ea276174e
|
data/Gemfile.lock
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
vgcal (0.2
|
|
4
|
+
vgcal (0.3.2)
|
|
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)
|
data/README.md
CHANGED
|
@@ -41,11 +41,12 @@ Usage:
|
|
|
41
41
|
vgcal show
|
|
42
42
|
|
|
43
43
|
Options:
|
|
44
|
-
-d, [--date=DATE]
|
|
45
|
-
-c, [--current-week
|
|
46
|
-
-n, [--next-week
|
|
47
|
-
-s, [--start-date=N]
|
|
48
|
-
-e, [--end-date=N]
|
|
44
|
+
-d, [--date=DATE] # Show relative date. ex.-1, +10
|
|
45
|
+
-c, [--current-week], [--no-current-week] # Show current week tasks
|
|
46
|
+
-n, [--next-week], [--no-next-week] # Show next week tasks
|
|
47
|
+
-s, [--start-date=N] # Start date. ex.20210701
|
|
48
|
+
-e, [--end-date=N] # End date. ex.20210728
|
|
49
|
+
-o, [--output=OUTPUT] # Output format. [text|json]
|
|
49
50
|
|
|
50
51
|
Show google calendar
|
|
51
52
|
$
|
|
@@ -61,8 +62,8 @@ $ vgcal show
|
|
|
61
62
|
Period: 2021-07-24T00:00:00+09:00 - 2021-07-24T23:59:59+09:00
|
|
62
63
|
|
|
63
64
|
My tasks: 5.25h(0.66day)
|
|
64
|
-
・all day task 1:
|
|
65
|
-
・all day task2:
|
|
65
|
+
・all day task 1: 0h
|
|
66
|
+
・all day task2: 0h
|
|
66
67
|
・meeting1: 2.0h
|
|
67
68
|
・meeting2: 0.25h
|
|
68
69
|
・meeting3: 3.0h
|
|
@@ -80,6 +81,30 @@ $ vgcal show -d +1
|
|
|
80
81
|
|
|
81
82
|
# Schedule for 2021/07/01 - 2021/07/28
|
|
82
83
|
$ vgcal show -s 20210701 -e 20210728
|
|
84
|
+
|
|
85
|
+
# Formatted json
|
|
86
|
+
$ vgcal show -o json | jq .
|
|
87
|
+
{
|
|
88
|
+
"start_date": "2021-09-05T00:00:00+09:00",
|
|
89
|
+
"end_date": "2021-09-05T23:59:59+09:00",
|
|
90
|
+
"tasks": [
|
|
91
|
+
{
|
|
92
|
+
"title": "all day task 1",
|
|
93
|
+
"time": 0,
|
|
94
|
+
"task_type": "my_task"
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
"title": "task a",
|
|
98
|
+
"time": 1,
|
|
99
|
+
"task_type": "my_task"
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
"title": "task b",
|
|
103
|
+
"time": 1,
|
|
104
|
+
"task_type": "my_task"
|
|
105
|
+
}
|
|
106
|
+
]
|
|
107
|
+
}
|
|
83
108
|
```
|
|
84
109
|
|
|
85
110
|
## Development
|
|
@@ -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)
|
|
@@ -21,32 +22,26 @@ module Vgcal
|
|
|
21
22
|
end
|
|
22
23
|
|
|
23
24
|
option :date, type: :string, aliases: '-d', desc: 'Show relative date. ex.-1, +10'
|
|
24
|
-
option :'current-week', type: :
|
|
25
|
-
option :'next-week', type: :
|
|
25
|
+
option :'current-week', type: :boolean, aliases: '-c', desc: 'Show current week tasks'
|
|
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
|
data/lib/vgcal/my_calendar.rb
CHANGED
|
@@ -8,29 +8,28 @@ 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)
|
|
32
31
|
if all_day_event?(e.start.date)
|
|
33
|
-
tasks_hash[e.summary] =
|
|
32
|
+
tasks_hash[e.summary] = 0
|
|
34
33
|
else
|
|
35
34
|
task_time = (e.end.date_time - e.start.date_time).to_f * 24
|
|
36
35
|
# 1日の中で同じタスク名が複数あったら時間を集計する。例.午前と午後それぞれでAプロジェクトに1時間スケジュール
|
|
@@ -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.2
|
|
4
|
+
version: 0.3.2
|
|
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-
|
|
11
|
+
date: 2021-09-05 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|