Skip to content

Instantly share code, notes, and snippets.

@davidalpert
Created September 11, 2013 21:15
Show Gist options
  • Select an option

  • Save davidalpert/6529900 to your computer and use it in GitHub Desktop.

Select an option

Save davidalpert/6529900 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'json'
require 'rake'
require 'date'
#include FileUtils
pattern_to_search = "./path/to/files/*.json"
def get_date_from_filename(f)
match = f.match /.*_(\d+)_(\d+)_(\d+)$/
year = match[1]
month = match[2]
day = match[3]
Date.new(year, month, day)
end
def read_one_file(f)
data = ""
File.open(f, "r") do |fileData|
data = JSON.parse(f)
end
data
end
puts "Scanning #{pattern_to_search}"
FileList[pattern_to_search].each do |f|
#puts "- reading: #{f}"
date = get_date_from_filename(f) rescue DateTime.now
data = read_one_file(f)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment