gcalgen 0.0.1
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 +7 -0
- data/.gitignore +17 -0
- data/Gemfile +11 -0
- data/LICENSE.txt +22 -0
- data/README.md +23 -0
- data/Rakefile +1 -0
- data/bin/gcalgen +23 -0
- data/gcalgen.gemspec +23 -0
- data/lib/gcalgen/config.rb +25 -0
- data/lib/gcalgen/event.rb +276 -0
- data/lib/gcalgen/every.rb +26 -0
- data/lib/gcalgen/version.rb +3 -0
- data/lib/gcalgen.rb +20 -0
- metadata +85 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f89666dd0a13e2411cfb70bb1379da58e8b85b59
|
4
|
+
data.tar.gz: dc9ce2aef77ba32d6f840dceed03c8569d057727
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c6e0e8fdae6f59c680c9c7ec80a2c70cb26b30f229f070d85ae30d673004b78a2c595cb852f216603398c29bdf74f813601c87e9bc4324290c0edef93de9aa64
|
7
|
+
data.tar.gz: e0096c754b9b6abfef32dc4862fd960af1243ccb6cab8d6a13b53f6e9e9c6e144cf8c2bf237050097d59be8a831acfa821bf3df356ead12be95fd67e47c75f23
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 いざわゆきみつ (Yukimitsu Izawa)
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# Gcalgen
|
2
|
+
|
3
|
+
Google calendar event generator
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem install gcalgen
|
10
|
+
|
11
|
+
and create ~/.gcalgenrc
|
12
|
+
|
13
|
+
## Usage
|
14
|
+
|
15
|
+
% gcalgen eventfile1 [eventfile2....]
|
16
|
+
|
17
|
+
## Contributing
|
18
|
+
|
19
|
+
1. Fork it
|
20
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
21
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
22
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
23
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/gcalgen
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'gcalgen'
|
4
|
+
include Gcalgen
|
5
|
+
|
6
|
+
if ARGV.size < 1
|
7
|
+
print "Google Calendar event generator - version #{VERSION}\n"
|
8
|
+
print "Usage:\n gcalgen datafile1 [datafile2 ....]\n"
|
9
|
+
exit 1
|
10
|
+
end
|
11
|
+
|
12
|
+
#
|
13
|
+
# load ~/.gcalgenrc
|
14
|
+
#
|
15
|
+
$myConfig = { }
|
16
|
+
load File.expand_path('~/.gcalgenrc')
|
17
|
+
|
18
|
+
#
|
19
|
+
# execute calendar
|
20
|
+
#
|
21
|
+
ARGV.each { |datafile|
|
22
|
+
load datafile
|
23
|
+
}
|
data/gcalgen.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'gcalgen/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "gcalgen"
|
8
|
+
spec.version = Gcalgen::VERSION
|
9
|
+
spec.authors = ["Yukimitsu Izawa"]
|
10
|
+
spec.email = ["izawa@izawa.org"]
|
11
|
+
spec.description = %q{Google Calendar event generator}
|
12
|
+
spec.summary = %q{Google Calendar event generator}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
|
2
|
+
class GcalConfig
|
3
|
+
attr_accessor :cal_name, :cal_feed, :cal_user, :cal_password
|
4
|
+
|
5
|
+
def initialize(name)
|
6
|
+
@cal_name = name
|
7
|
+
end
|
8
|
+
|
9
|
+
####
|
10
|
+
## DSL functions
|
11
|
+
####
|
12
|
+
|
13
|
+
def feed(feed)
|
14
|
+
@cal_feed = feed
|
15
|
+
end
|
16
|
+
|
17
|
+
def user(user)
|
18
|
+
@cal_user = user
|
19
|
+
end
|
20
|
+
|
21
|
+
def password(password)
|
22
|
+
@cal_password = password
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
@@ -0,0 +1,276 @@
|
|
1
|
+
require 'gcalapi'
|
2
|
+
require 'active_support/time'
|
3
|
+
require 'calendar/japanese/holiday'
|
4
|
+
|
5
|
+
require 'pry'
|
6
|
+
|
7
|
+
class Event
|
8
|
+
attr_accessor :title, :start_time, :end_time, :desc, :main_method, :sub_method, :date, :location, :range_begins, :range_ends, :allday, :every
|
9
|
+
attr_accessor :cal_name
|
10
|
+
|
11
|
+
def initialize(title)
|
12
|
+
@title = title
|
13
|
+
end
|
14
|
+
|
15
|
+
####
|
16
|
+
## DSL functions
|
17
|
+
####
|
18
|
+
|
19
|
+
def on(date)
|
20
|
+
@date=DateTime.parse(date)
|
21
|
+
@date = @date.change(:offset => DateTime.now.zone)
|
22
|
+
end
|
23
|
+
|
24
|
+
def starts(start_time)
|
25
|
+
@start_time = start_time
|
26
|
+
end
|
27
|
+
|
28
|
+
def ends(end_time)
|
29
|
+
@end_time = end_time
|
30
|
+
end
|
31
|
+
|
32
|
+
def at(location)
|
33
|
+
@location = location
|
34
|
+
end
|
35
|
+
|
36
|
+
def desc(desc)
|
37
|
+
@desc = desc
|
38
|
+
end
|
39
|
+
|
40
|
+
def all_day
|
41
|
+
@allday = true
|
42
|
+
end
|
43
|
+
|
44
|
+
def every(method, &block)
|
45
|
+
@every = Every.new(method)
|
46
|
+
@every.instance_eval &block if block_given?
|
47
|
+
end
|
48
|
+
|
49
|
+
def range_begins(date)
|
50
|
+
@range_begins = DateTime.parse(date)
|
51
|
+
@range_begins = @range_begins.change(:offset => DateTime.now.zone)
|
52
|
+
end
|
53
|
+
|
54
|
+
def range_ends(date)
|
55
|
+
@range_ends = DateTime.parse(date)
|
56
|
+
@range_ends = @range_ends.change(:offset => DateTime.now.zone)
|
57
|
+
end
|
58
|
+
|
59
|
+
def calendar(cal_name)
|
60
|
+
@cal_name = cal_name
|
61
|
+
end
|
62
|
+
|
63
|
+
|
64
|
+
####
|
65
|
+
## internal methods
|
66
|
+
####
|
67
|
+
|
68
|
+
def _check_holiday(date)
|
69
|
+
d = date.to_date.extend Calendar::Japanese::Holiday
|
70
|
+
d.holiday?
|
71
|
+
end
|
72
|
+
|
73
|
+
def _get_first(date, business_day)
|
74
|
+
first = date.beginning_of_month
|
75
|
+
if business_day
|
76
|
+
while _check_holiday(first)
|
77
|
+
first += 1.day
|
78
|
+
end
|
79
|
+
end
|
80
|
+
first
|
81
|
+
end
|
82
|
+
|
83
|
+
def _get_last(date, business_day)
|
84
|
+
last = date.end_of_month
|
85
|
+
if business_day
|
86
|
+
while _check_holiday(last)
|
87
|
+
last -= 1.day
|
88
|
+
end
|
89
|
+
end
|
90
|
+
last
|
91
|
+
end
|
92
|
+
|
93
|
+
def _generate_st_en(today)
|
94
|
+
allday = true if @allday
|
95
|
+
if @start_time =~/(\d\d):(\d\d)/
|
96
|
+
st = today.to_time
|
97
|
+
st += $1.to_i.hours
|
98
|
+
st += $2.to_i.minutes
|
99
|
+
if @end_time =~/(\d\d):(\d\d)/
|
100
|
+
en = today.to_time
|
101
|
+
en+= $1.to_i.hours
|
102
|
+
en+= $2.to_i.minutes
|
103
|
+
else
|
104
|
+
en = st + 1.hour
|
105
|
+
end
|
106
|
+
else
|
107
|
+
st = today.in_time_zone
|
108
|
+
en = today.in_time_zone
|
109
|
+
allday = true
|
110
|
+
end
|
111
|
+
return {:st => st, :en => en, :allday => allday}
|
112
|
+
end
|
113
|
+
|
114
|
+
def _generate_weekly
|
115
|
+
ret = []
|
116
|
+
|
117
|
+
if @range_begins
|
118
|
+
today = @range_begins
|
119
|
+
else
|
120
|
+
today = Date.today
|
121
|
+
today = today.change(:offset => DateTime.now.zone)
|
122
|
+
end
|
123
|
+
if @range_ends
|
124
|
+
limit = @range_ends
|
125
|
+
else
|
126
|
+
limit = today + 3.month
|
127
|
+
limit = limit.change(:offset => DateTime.now.zone)
|
128
|
+
end
|
129
|
+
|
130
|
+
@every.weekday = today.strftime('%A') unless @every.weekday
|
131
|
+
|
132
|
+
# search matched wday forward
|
133
|
+
while today.strftime('%A') !~ /#{@every.weekday}/i
|
134
|
+
today += 1.day
|
135
|
+
end
|
136
|
+
# generate array of st,en
|
137
|
+
while today < limit
|
138
|
+
if _check_holiday(today)
|
139
|
+
if @every.business
|
140
|
+
if @every.shift
|
141
|
+
while _check_holiday(today)
|
142
|
+
today += 1.day
|
143
|
+
end
|
144
|
+
else
|
145
|
+
today += 7.days
|
146
|
+
next
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
ret << _generate_st_en(today)
|
151
|
+
today = today.next_week
|
152
|
+
end
|
153
|
+
ret
|
154
|
+
end
|
155
|
+
|
156
|
+
def _generate_monthly
|
157
|
+
ret = []
|
158
|
+
|
159
|
+
if @range_begins
|
160
|
+
today = @range_begins
|
161
|
+
else
|
162
|
+
today = Date.today
|
163
|
+
today = today.change(:offset => DateTime.now.zone)
|
164
|
+
end
|
165
|
+
|
166
|
+
if @range_ends
|
167
|
+
limit = @range_ends
|
168
|
+
else
|
169
|
+
limit = today + 6.month
|
170
|
+
limit = limit.change(:offset => DateTime.now.zone)
|
171
|
+
end
|
172
|
+
|
173
|
+
# generate array of st/en
|
174
|
+
while today < limit
|
175
|
+
if @every.first_flg
|
176
|
+
today = _get_first(today, @every.business_day)
|
177
|
+
elsif @every.last_flg
|
178
|
+
today = _get_last(today, @every.business_day)
|
179
|
+
end
|
180
|
+
today = today.beginning_of_day
|
181
|
+
|
182
|
+
## st time/ en time
|
183
|
+
##
|
184
|
+
ret << _generate_st_en(today)
|
185
|
+
today = today.next_month.beginning_of_month
|
186
|
+
end
|
187
|
+
ret
|
188
|
+
end
|
189
|
+
|
190
|
+
def _generate_annualy
|
191
|
+
ret = []
|
192
|
+
|
193
|
+
today = @date
|
194
|
+
if @range_begins
|
195
|
+
while @range_begins > today
|
196
|
+
today = today.next_year
|
197
|
+
end
|
198
|
+
end
|
199
|
+
if @range_ends
|
200
|
+
limit = @range_ends
|
201
|
+
else
|
202
|
+
limit = today + 5.years
|
203
|
+
limit = limit.change(:offset => DateTime.now.zone)
|
204
|
+
end
|
205
|
+
|
206
|
+
# generate array of st/en
|
207
|
+
while today < limit
|
208
|
+
## st time/ en time
|
209
|
+
##
|
210
|
+
ret << _generate_st_en(today)
|
211
|
+
today = today.next_year
|
212
|
+
end
|
213
|
+
ret
|
214
|
+
end
|
215
|
+
|
216
|
+
def _generate_oneshot
|
217
|
+
ret = []
|
218
|
+
if @start_time
|
219
|
+
today = @date.beginning_of_day
|
220
|
+
today = DateTime.parse(@date.strftime("%Y/%m/%d ") + @start_time + DateTime.now.zone)
|
221
|
+
st = today
|
222
|
+
if @end_time
|
223
|
+
today = @date.beginning_of_day
|
224
|
+
today = DateTime.parse(@date.strftime("%Y/%m/%d ") + @end_time + DateTime.now.zone)
|
225
|
+
en=today
|
226
|
+
else
|
227
|
+
en = st + 1.hour
|
228
|
+
end
|
229
|
+
else
|
230
|
+
st = @date.beginning_of_day
|
231
|
+
en= @date.beginning_of_day
|
232
|
+
allday = true
|
233
|
+
end
|
234
|
+
ret << {:st => st, :en => en, :allday => allday}
|
235
|
+
end
|
236
|
+
|
237
|
+
def generate_gcalevent
|
238
|
+
ret = []
|
239
|
+
|
240
|
+
if @cal_name
|
241
|
+
user = $myConfig[@cal_name].cal_user
|
242
|
+
password = $myConfig[@cal_name].cal_password
|
243
|
+
feed = $myConfig[@cal_name].cal_feed
|
244
|
+
else
|
245
|
+
user = $myConfig['default'].cal_user
|
246
|
+
password = $myConfig['default'].cal_password
|
247
|
+
feed = $myConfig['default'].cal_feed
|
248
|
+
end
|
249
|
+
|
250
|
+
cal = GoogleCalendar::Calendar.new(GoogleCalendar::Service.new(user, password), feed)
|
251
|
+
|
252
|
+
if @every
|
253
|
+
if @every.method =~ /week/i
|
254
|
+
st_en = _generate_weekly
|
255
|
+
elsif @every.method =~ /month/i
|
256
|
+
st_en = _generate_monthly
|
257
|
+
elsif @every.method =~ /year/i
|
258
|
+
st_en = _generate_annualy
|
259
|
+
end
|
260
|
+
else # one shot event
|
261
|
+
st_en = _generate_oneshot
|
262
|
+
end
|
263
|
+
|
264
|
+
st_en.each {|val|
|
265
|
+
event = cal.create_event
|
266
|
+
event.title = @title
|
267
|
+
event.desc = @desc
|
268
|
+
event.where = @location
|
269
|
+
event.allday = val[:allday]
|
270
|
+
event.st = val[:st]
|
271
|
+
event.en = val[:en]
|
272
|
+
ret << event
|
273
|
+
}
|
274
|
+
ret
|
275
|
+
end
|
276
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
class Every
|
2
|
+
attr_accessor :method, :weekday, :mmdd, :first_flg, :last_flg, :shift, :business
|
3
|
+
def initialize(method)
|
4
|
+
@method = method
|
5
|
+
end
|
6
|
+
|
7
|
+
def wday(weekday)
|
8
|
+
@weekday = weekday
|
9
|
+
end
|
10
|
+
|
11
|
+
def first
|
12
|
+
@first_flg = true
|
13
|
+
end
|
14
|
+
|
15
|
+
def last
|
16
|
+
@last_flg = true
|
17
|
+
end
|
18
|
+
|
19
|
+
def shift_enable
|
20
|
+
@shift = true
|
21
|
+
end
|
22
|
+
|
23
|
+
def business_day
|
24
|
+
@business = true
|
25
|
+
end
|
26
|
+
end
|
data/lib/gcalgen.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require "gcalgen/version"
|
2
|
+
require 'gcalgen/config'
|
3
|
+
require 'gcalgen/event'
|
4
|
+
require 'gcalgen/every'
|
5
|
+
|
6
|
+
module Gcalgen
|
7
|
+
def def_calendar(name, &block)
|
8
|
+
c = GcalConfig.new(name)
|
9
|
+
c.instance_eval &block
|
10
|
+
$myConfig[name] = c
|
11
|
+
end
|
12
|
+
|
13
|
+
def event(title, &block)
|
14
|
+
c = Event.new(title)
|
15
|
+
c.instance_eval &block
|
16
|
+
c.generate_gcalevent.each { |event|
|
17
|
+
event.save!
|
18
|
+
}
|
19
|
+
end
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gcalgen
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Yukimitsu Izawa
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-08-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Google Calendar event generator
|
42
|
+
email:
|
43
|
+
- izawa@izawa.org
|
44
|
+
executables:
|
45
|
+
- gcalgen
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- .gitignore
|
50
|
+
- Gemfile
|
51
|
+
- LICENSE.txt
|
52
|
+
- README.md
|
53
|
+
- Rakefile
|
54
|
+
- bin/gcalgen
|
55
|
+
- gcalgen.gemspec
|
56
|
+
- lib/gcalgen.rb
|
57
|
+
- lib/gcalgen/config.rb
|
58
|
+
- lib/gcalgen/event.rb
|
59
|
+
- lib/gcalgen/every.rb
|
60
|
+
- lib/gcalgen/version.rb
|
61
|
+
homepage: ''
|
62
|
+
licenses:
|
63
|
+
- MIT
|
64
|
+
metadata: {}
|
65
|
+
post_install_message:
|
66
|
+
rdoc_options: []
|
67
|
+
require_paths:
|
68
|
+
- lib
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - '>='
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - '>='
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
requirements: []
|
80
|
+
rubyforge_project:
|
81
|
+
rubygems_version: 2.0.6
|
82
|
+
signing_key:
|
83
|
+
specification_version: 4
|
84
|
+
summary: Google Calendar event generator
|
85
|
+
test_files: []
|