forked from kenpratt/dbox
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsample_polling_script.rb
More file actions
45 lines (38 loc) · 879 Bytes
/
sample_polling_script.rb
File metadata and controls
45 lines (38 loc) · 879 Bytes
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
#!/usr/bin/env ruby
require "rubygems"
require "dbox"
ENV["DROPBOX_APP_KEY"] = "cmlrrjd3j0gbend"
ENV["DROPBOX_APP_SECRET"] = "uvuulp75xf9jffl"
ENV["DROPBOX_AUTH_KEY"] = "v4d7l1rez1czksn"
ENV["DROPBOX_AUTH_SECRET"] = "pqej9rmnj0i1gcxr4"
LOGFILE = "/home/myuser/dbox.log"
LOCAL_PATH = "/home/myuser/dropbox"
REMOTE_PATH = "/stuff/myfolder"
INTERVAL = 60 # time between syncs, in seconds
LOGGER = Logger.new(LOGFILE, 1, 1024000)
LOGGER.level = Logger::INFO
def main
while 1
begin
sync
rescue Interrupt => e
exit 0
rescue Exception => e
LOGGER.error e
end
sleep INTERVAL
end
end
def sync
unless Dbox.exists?(LOCAL_PATH)
LOGGER.info "Cloning"
Dbox.clone(REMOTE_PATH, LOCAL_PATH)
LOGGER.info "Done"
else
LOGGER.info "Syncing"
Dbox.push(LOCAL_PATH)
Dbox.pull(LOCAL_PATH)
LOGGER.info "Done"
end
end
main