Skip to content

Instantly share code, notes, and snippets.

@valpackett
Created March 5, 2016 14:05
Show Gist options
  • Save valpackett/274717f137c22eecd3d5 to your computer and use it in GitHub Desktop.
Save valpackett/274717f137c22eecd3d5 to your computer and use it in GitHub Desktop.
Convert Sweetroll entires' file names to new, date-based format
%w(date json).each { |m| require m }
Dir[File.join ARGV.first, "**/*.json"].each do |path|
fname = File.basename(path)
next if (fname =~ /^\d+-.*/).nil?
pub = (JSON.parse(File.read(path))["properties"] || {})["published"] || []
next if pub.empty?
newpath = File.join File.dirname(path), fname.gsub(/^\d+/, DateTime.parse(pub.first).strftime("%s"))
puts "#{path} => #{newpath}"
File.rename path, newpath
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment