-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsyncher.rb
executable file
·80 lines (63 loc) · 2.11 KB
/
syncher.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/env ruby
require 'time'
require 'optparse'
# Runs a block of code without warnings.
def silence_warnings(&block)
warn_level = $VERBOSE
$VERBOSE = nil
result = block.call
$VERBOSE = warn_level
result
end
def synch(auto=true, full=false, verbose=false)
exchanger = Exchanger.new
google_calendar = GoogleCalendarWrapper.new
auto && google_calendar.login_with_token || google_calendar.login_with_or_without_token
today = Date.today
items = (full) ? exchanger.list_calendar_items_between(today - 180, today + 180) : exchanger.list_calendar_items_since(today)
items.each { |item| CalendarItem.synch_and_save(item, verbose) {|item| p item.to_json if verbose; google_calendar.save(item)} }
end
options = {}
opt_parser = OptionParser.new do |opt|
opt.banner = "Usage: syncher.rb [OPTIONS]"
opt.separator ""
opt.separator "Options"
opt.on("-f","--full","takes events that occur until 180 days behind and ahead of today") do |name|
options[:full] = true
end
opt.on("-a","--auto","assumes a key was generated and won't prompt for Google authorization") do |name|
options[:auto] = true
end
opt.on("-v","--verbose","outputs the synched items") do |name|
options[:verbose] = true
end
opt.on("-s","--setup","setups Outlook configuration and credentials") do |name|
options[:setup] = true
end
opt.on("-c","--calendar","setups Google Calendar Id") do |name|
options[:calendar] = true
end
opt.on("-p","--password","changes Outlook password") do |name|
options[:password] = true
end
opt.on("-h","--help","help") do
puts opt_parser
puts "\nWARNING: If you don't explicitly set MONGOID_ENV, production config will be used!"
exit
end
end
opt_parser.parse!
silence_warnings do
require_relative 'lib/exchanger'
require_relative 'lib/calendar_item'
require_relative 'lib/google_calendar_wrapper'
if options[:setup]
Exchanger.configure
elsif options[:password]
Exchanger.set_password
elsif options[:calendar]
GoogleCalendarWrapper.setup_calendar
else
synch(options[:auto], options[:full], options[:verbose])
end
end