vgcal 0.2.3 → 0.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e8dd7c78c6a1c70737ac7aa5f7d9e8e0d32060fb63adf0447db01acdaf5376c0
4
- data.tar.gz: 5fbb39780a006902a4ec96105a0f773cb56d2b073ebd268e415a0789fd4f3039
3
+ metadata.gz: 9a8a4820ac5ec51ae8603b18a047717b7c0b12a143c70b04bd4dcff5fe21a349
4
+ data.tar.gz: 0e97596aecf4228d7c132a2960dcca84f8087402af8eeee99a1ad715432c6b8f
5
5
  SHA512:
6
- metadata.gz: '0748ef604645d4c5bce2a495a1373455b9c88773a6b34b0abd27fd8ef40a2a17d168d61de096223524cc92a2f145b79553ebbc890bdff1fb5c90f55f8cbc69fd'
7
- data.tar.gz: a7f7bd82e58d3f63706f7711bcce7215ea3c2803fa9df51e1e406a0c62204f3eaaecc45bb4a1bdb337d599c74197ce9dd17f28540c653280d0900d8aa333983f
6
+ metadata.gz: b4da59f8dc452af1ddcc90303a498cdf19af129fa8aa31f69cab379c34d674fc0d1709bfb23b04f958ff319b63cc665bbe4dd17b90a459fa88443a4af1ac7787
7
+ data.tar.gz: f5c2104b3e9b3928e5d16ab7a6332f32d3dc51c84964d89604a1d285550897cca16f8451017cd337c7234f8b043f41c39578119345d582d242f84ad9635fc043
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 3.0.1
1
+ 3.0.4
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- vgcal (0.2.3)
4
+ vgcal (0.3.3)
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.5.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.16.2)
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.14)
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.0)
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.15.0)
120
- addressable (~> 2.3)
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)
@@ -131,6 +133,7 @@ GEM
131
133
  zeitwerk (2.4.2)
132
134
 
133
135
  PLATFORMS
136
+ arm64-darwin-21
134
137
  x86_64-darwin-19
135
138
 
136
139
  DEPENDENCIES
@@ -141,4 +144,4 @@ DEPENDENCIES
141
144
  vgcal!
142
145
 
143
146
  BUNDLED WITH
144
- 2.2.15
147
+ 2.2.33
data/README.md CHANGED
@@ -46,6 +46,7 @@ Options:
46
46
  -n, [--next-week], [--no-next-week] # Show next week tasks
47
47
  -s, [--start-date=N] # Start date. ex.20210701
48
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: all day
65
- ・all day task2: all day
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,10 +14,11 @@ module Vgcal
13
14
  def init
14
15
  vgcal_dir = "#{Dir.home}/.vgcal"
15
16
  cred_json = "#{vgcal_dir}/credentials.json"
16
- dot_env = "#{vgcal_dir}/.env"
17
+ dot_env = "#{vgcal_dir}/.env"
18
+ gem_root = File.expand_path '../../../', __dir__
17
19
  Dir.mkdir(vgcal_dir, 0o755) unless Dir.exist?(vgcal_dir)
18
- FileUtils.cp('template-credentials.json', cred_json) unless File.exist?(cred_json)
19
- FileUtils.cp('template.env', dot_env) unless File.exist?(dot_env)
20
+ FileUtils.cp(File.join(gem_root,'template-credentials.json'), cred_json) unless File.exist?(cred_json)
21
+ FileUtils.cp(File.join(gem_root,'template.env'), dot_env) unless File.exist?(dot_env)
20
22
  puts "Fix the __FIX_ME__ in #{cred_json} and #{dot_env}"
21
23
  end
22
24
 
@@ -25,28 +27,22 @@ module Vgcal
25
27
  option :'next-week', type: :boolean, aliases: '-n', desc: 'Show next week tasks'
26
28
  option :'start-date', type: :numeric, aliases: '-s', desc: 'Start date. ex.20210701'
27
29
  option :'end-date', type: :numeric, aliases: '-e', desc: 'End date. ex.20210728'
30
+ option :'output', type: :string, aliases: '-o', desc: 'Output format. [text|json]'
28
31
 
29
32
  desc 'show', 'Show google calendar'
30
33
 
31
34
  def show
32
35
  Dotenv.load("#{Dir.home}/.vgcal/.env")
33
- puts "Period: #{start_date} - #{end_date}"
34
- puts
35
- mcal = MyCalendar.new(start_date, end_date)
36
+ mcal = MyCalendar.new(start_date, end_date)
36
37
  events = mcal.events
37
- tasks = mcal.tasks(events)
38
- puts "My tasks: #{tasks[0]}h(#{(tasks[0] / 8).round(2)}day)"
39
- tasks[1].each do |task|
40
- if task[1].is_a?(String)
41
- puts " ・#{task[0]}: #{task[1]}"
42
- else
43
- puts " ・#{task[0]}: #{task[1]}h"
44
- end
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"
38
+
39
+ case options[:output]
40
+ when 'json'
41
+ stdout_json(mcal.tasks(events), mcal.invited_meetings(events))
42
+ when 'text'
43
+ stdout_default(mcal.tasks(events), mcal.invited_meetings(events))
44
+ else
45
+ stdout_default(mcal.tasks(events), mcal.invited_meetings(events))
50
46
  end
51
47
  end
52
48
 
@@ -58,6 +54,55 @@ module Vgcal
58
54
 
59
55
  private
60
56
 
57
+ def stdout_json(my_tasks, invited_meetings)
58
+ hash = {
59
+ 'start_date': "#{start_date}",
60
+ 'end_date': "#{end_date}",
61
+ 'tasks': []
62
+ }
63
+ my_tasks.each do |task|
64
+ hash[:tasks].push ({
65
+ "title": task[0],
66
+ "time": task[1],
67
+ "task_type": 'my_task'
68
+ })
69
+ end
70
+ invited_meetings.each do |meeting|
71
+ hash[:tasks].push ({
72
+ 'title': meeting[0],
73
+ 'time': meeting[1],
74
+ 'task_type': 'invited_meeting'
75
+ })
76
+ end
77
+ puts hash.to_json
78
+ end
79
+
80
+ def stdout_default(my_tasks, invited_meetings)
81
+ puts "Period: #{start_date} - #{end_date}"
82
+ puts
83
+ my_task_time = 0
84
+ my_tasks.select do |n|
85
+ my_task_time += n[1]
86
+ end
87
+ puts "My tasks: #{my_task_time}h(#{(my_task_time / 8).round(2)}day)"
88
+ my_tasks.each do |task|
89
+ if my_tasks.is_a?(String)
90
+ puts " ・#{task[0]}: #{task[1]}"
91
+ else
92
+ puts " ・#{task[0]}: #{task[1]}h"
93
+ end
94
+ end
95
+
96
+ meeting_time = 0
97
+ invited_meetings.select do |m|
98
+ meeting_time += m[1]
99
+ end
100
+ puts "Invited meetings: #{meeting_time}h(#{(meeting_time / 8).round(2)}day)"
101
+ invited_meetings.each do |meeting|
102
+ puts " ・#{meeting[0]}: #{meeting[1]}h"
103
+ end
104
+ end
105
+
61
106
  def start_date
62
107
  s_date = if options[:'current-week']
63
108
  if Date.today.sunday?
@@ -97,7 +142,7 @@ module Vgcal
97
142
  end
98
143
  elsif options[:'next-week']
99
144
  if Date.today.sunday?
100
- (Date.today + 7).to_s
145
+ (Date.today + 13).to_s
101
146
  else
102
147
  (Date.today + 7 + (6 - Date.today.wday)).to_s
103
148
  end
@@ -113,11 +158,7 @@ module Vgcal
113
158
  elsif options['start-date'] && options['end-date']
114
159
  Date.parse(options['end-date'].to_s)
115
160
  else
116
- if Date.today.sunday?
117
- (Date.today + 6).to_s
118
- else
119
- (Date.today + (6 - Date.today.wday)).to_s
120
- end
161
+ Date.today.to_s
121
162
  end
122
163
  "#{e_date}T23:59:59+09:00"
123
164
  end
@@ -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 = end_date
11
+ @end_date = end_date
12
12
  end
13
13
 
14
14
  def events
15
- service = Google::Apis::CalendarV3::CalendarService.new
15
+ service = Google::Apis::CalendarV3::CalendarService.new
16
16
  service.authorization = Vgcal::Authorizer.new.credentials
17
- calendar_id = 'primary'
17
+ calendar_id = 'primary'
18
18
  service.list_events(calendar_id,
19
- max_results: 100,
19
+ max_results: 100,
20
20
  single_events: true,
21
- order_by: 'startTime',
22
- time_min: @start_date,
23
- time_max: @end_date)
21
+ order_by: 'startTime',
22
+ time_min: @start_date,
23
+ time_max: @end_date)
24
24
  end
25
25
 
26
- # return: [4.25, [["daily scrum", 0.25], ["SRE定例", 1.0], ["test", 2.0], ["task2", 1.0]]]
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] = 'all day'
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
- [total_meeting_times, tasks_hash.sort.to_a]
44
+ tasks_hash.sort.to_a
50
45
  end
51
46
 
52
- # return: [2.25, [["朝会", 0.5], ["daily scrum", 0.25], ["SRE朝会", 0.5], ["定例", 1.0]]]
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
- [total_meeting_times, tasks_hash.sort.to_a]
66
+ tasks_hash.sort.to_a
77
67
  end
78
68
 
79
69
  private
data/lib/vgcal/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Vgcal
4
- VERSION = '0.2.3'
4
+ VERSION = '0.4.0'
5
5
  end
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.3
4
+ version: 0.4.0
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-04 00:00:00.000000000 Z
11
+ date: 2022-08-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -155,7 +155,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
155
155
  - !ruby/object:Gem::Version
156
156
  version: '0'
157
157
  requirements: []
158
- rubygems_version: 3.2.15
158
+ rubygems_version: 3.2.33
159
159
  signing_key:
160
160
  specification_version: 4
161
161
  summary: "%q{The vgcal command simplifies the display of Google Calendar events.}"