Created
July 29, 2016 06:55
-
-
Save meetme2meat/1ed956e5362dfd443c9349efad09c044 to your computer and use it in GitHub Desktop.
Test rb file.
This file contains 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
require 'rubygems' | |
$zone = "-06:00" | |
require 'pry' | |
#inspect.txt | |
#rinspect.txt | |
MONTH= {"Jan" => 1,"Feb" =>2,"Mar" => 3,"Apr" => 4,"May" => 5,"Jun" => 6,"Jul" => 7,"Aug" => 8,"Sep" => 9,"Oct" => 10,"Nov" => 11,"Dec" => 12}.freeze | |
def find_time(time) | |
day = time.match(/^\d{2}/)[0].to_i | |
month = MONTH[time.match(/[A-Z][a-z]{2}/)[0]] | |
year = time.match(/\d{4}/)[0].to_i | |
hour,min,sec = time.scan(/(\d{2}):(\d{2}):(\d{2})/)[0].collect(&:to_i) | |
Time.new(year,month,day,hour,min,sec,$zone) | |
end | |
def extract_time(data) | |
time = data.match(/\d{2} Jul 2016 \d{2}:\d{2}:\d{2}/)[0] | |
find_time(time) | |
end | |
File.open('inspect.txt','r') do |file| | |
while(!file.eof?) | |
print"\r at line #{file.lineno} " | |
data = file.readline | |
punch_time = extract_time(data) | |
message_id = data.match(/\w{10}/)[0] | |
grep_string = "grep #{message_id} #{Dir.pwd}/rinspect.txt" | |
output = `#{grep_string}`.split("\n") | |
all_times = output.map! { |s| extract_time(s)} | |
puts message_id unless all_times.any? { |i| (i-punch_time) < 60 } | |
end | |
end | |
# Time.new(2016,7,19,02,17,32,"-04:00") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment