Created
April 14, 2013 03:41
-
-
Save indirect/5381346 to your computer and use it in GitHub Desktop.
Restore the file creation and modification timestamps using the Dropbox API after the Dropbox client app throws them away
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'yaml' | |
require 'time' | |
APP_KEY = "your app key" | |
APP_SECRET = "your app secret" | |
TOKEN_KEY = nil | |
TOKEN_SECRET = nil | |
lib = File.expand_path("../dropbox-sdk/lib", __FILE__) | |
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) | |
require 'dropbox_sdk' | |
ACCESS_TYPE = :dropbox | |
session = DropboxSession.new(APP_KEY, APP_SECRET) | |
if TOKEN_KEY | |
session.set_access_token(TOKEN_KEY, TOKEN_SECRET) | |
else | |
session.get_request_token | |
system "open", session.get_authorize_url | |
puts "waiting for authorization..." | |
until token = (session.get_access_token rescue nil) | |
print "."; sleep 2 | |
end | |
puts "here's your token info:" | |
p token | |
puts "copy the token key and secret into the script and run it" | |
end | |
client = DropboxClient.new(session, ACCESS_TYPE) | |
metadata = client.metadata('/Paperwork/Unsorted') | |
files = metadata["contents"] | |
files.each do |file| | |
timestr = dbtime(file["client_mtime"]) | |
client_time = Time.strptime(timestr, "%a, %d %b %Y %H:%M:%S %z") | |
path = File.expand_path(File.join("~/Dropbox", file["path"])) | |
touchtime = client_time.strftime("%Y%m%d%H%M") | |
cmd = %|touch -t #{touchtime} "#{path}"| | |
p cmd | |
system cmd | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment