Skip to content

Instantly share code, notes, and snippets.

@advorak
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save advorak/a7234910cab42c361d87 to your computer and use it in GitHub Desktop.
Save advorak/a7234910cab42c361d87 to your computer and use it in GitHub Desktop.
@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
@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
@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