Last active
August 29, 2015 14:03
-
-
Save advorak/a7234910cab42c361d87 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
@user = User.find_by(file_number: ENV['FILE_NUMBER']) | |
@current_message = '' | |
@current_data = '' | |
while(data = @current_data.to_s + STDIN.read(100).to_s) | |
@current_data = '' | |
data.each_line do |line| | |
if line.match(/\n$/) | |
if line.match(/^\d{2}\/\d{2}\s\d{2}:\d{2}:\d{2}\.\d{2}\s/) | |
UnimaticMessage.create user: @user, data: @current_message | |
@current_message = line | |
else | |
@current_message += line | |
end | |
else | |
@current_data = line | |
end | |
end | |
sleep 0.25 | |
end |
This file contains hidden or 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
@current_data = '' | |
while(data = @current_data.to_s + STDIN.read(100).to_s) | |
@current_data = '' | |
messages = data.lines.slice_before(/^\d{2}\/\d{2}/).collect(&:join) | |
messages.each do |message| | |
if message.join.match(/\n$/) | |
UnimaticMessage.create user_id: ENV['DB_USER_ID'], data: message | |
else | |
@current_data = '' | |
end | |
end | |
sleep 0.25 | |
end |
This file contains hidden or 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
@user = User.find_by(file_number: ENV['FILE_NUMBER']) | |
@current_line = '' | |
while(STDIN) | |
begin | |
if(line = STDIN.readline) | |
if line.match(/^\d{2}\/\d{2}\s\d{2}:\d{2}:\d{2}\.\d{2}\s/) | |
#@lines.push @current_line | |
UnimaticMessage.create data: @current_line | |
@current_line = line | |
else | |
@current_line += line | |
end | |
#print "#{@line_position += 1}: " | |
#print line | |
end | |
#puts "\n"*10 | |
#puts @lines.inspect | |
rescue EOFError | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment