Skip to content

Instantly share code, notes, and snippets.

@southly
Created October 15, 2017 13:21
Show Gist options
  • Save southly/a1b10e53b1734397bb655f64c539e086 to your computer and use it in GitHub Desktop.
Save southly/a1b10e53b1734397bb655f64c539e086 to your computer and use it in GitHub Desktop.
narou send の代わり
#!/usr/bin/ruby
# -*- coding: utf-8 -*-
require 'fileutils'
require 'pathname'
require 'win32ole'
SYNC_PATH = "documents/web"
def get_kindle_path(volume_name = "Kindle")
fso = WIN32OLE.new("Scripting.FileSystemObject")
drives = fso.Drives
drives.each do |drive|
next unless drive.IsReady
vol = drive.VolumeName rescue ""
if vol.casecmp(volume_name) == 0
return Pathname.new("#{drive.DriveLetter}:").join(SYNC_PATH)
end
end
nil
end
def sync(src, dest)
return unless File.directory?(src)
return unless File.directory?(dest)
puts "Sync:"
puts " src: %s" % src
puts " dest: %s" % dest
for f in Dir.glob(File.join(dest, "*.mobi").encode('utf-8'))
b = File.basename(f)
s = File.join(src, b)
if File.exist?(s) && File::Stat.new(f).mtime < File::Stat.new(s).mtime
puts "... update %s" % b
FileUtils.cp(s, f)
end
end
puts "Done."
end
if __FILE__ == $0
s = File.absolute_path("D:/kindle")
d = File.absolute_path("C:/Users/xxx/Documents/My Kindle Content")
l = ARGV.length
if l > 0
s = File.absolute_path(ARGV[0]) if l > 0
d = File.absolute_path(ARGV[1]) if l > 1
sync(s, d)
else
sync(s, d)
puts
kindle = get_kindle_path
sync(s, File.absolute_path(kindle)) if kindle
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment