Skip to content

Instantly share code, notes, and snippets.

@take-cheeze
Created November 21, 2012 15:42
Show Gist options
  • Select an option

  • Save take-cheeze/4125529 to your computer and use it in GitHub Desktop.

Select an option

Save take-cheeze/4125529 to your computer and use it in GitHub Desktop.
PDF sending script
#!/usr/bin/env ruby
chunks = []
current_chunk = []
current_chunk_size = 0
CHUNK_MAX = 25
CHUNK_SIZE_MAX = 1000 * 1000 * 20
KINDLE_DIR = '%s/Dropbox/Kindle/' % [ENV['HOME']]
Dir.foreach(KINDLE_DIR) { |x|
filename = '"' + KINDLE_DIR + x + '"'
filesize = File.size(filename.gsub(/"/, ''))
if not /\.pdf$/i.match(x) or filesize > CHUNK_SIZE_MAX
next
end
if current_chunk.length >= CHUNK_MAX or (current_chunk_size + filesize) > CHUNK_SIZE_MAX
chunks.push(current_chunk)
current_chunk = []
current_chunk_size = 0
end
current_chunk_size += filesize
current_chunk.push(filename)
}
if not current_chunk.empty?
chunks.push(current_chunk)
end
chunks.each_index {|i|
print '%4d / %4d: ' % [i + 1, chunks.length]
raise "assert" unless system('sendKindle %s' % chunks[i].join(' '))
for f in chunks[i]
File.delete(f.gsub(/"/, ''))
end
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment