Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $lines = [] #Global array to store lines in
- $htmlhead = '<div class="block">\n <h1>Chat</h1>\n'
- $htmlfoot = ' </div>'
- def parse_file
- $lines = [] #Clear array in case this is looped instead of run in cron
- f = File.new("server.log") #Load server log
- f.each do |line|
- match = /^((\d+-\d+-\d+)\s(\d+:\d+:\d+) \[INFO\] (<(.+?)>\s+(?!P\s)(.+)))$/.match(line) #match regex against line
- # Example for: 2011-03-30 10:48:47 [INFO] <pname023> test message thing
- # [1] = 2011-03-30 10:48:47 [INFO] <pname023> test message thing
- # [2] = 2011-03-30
- # [3] = 10:40:47
- # [4] = <pname023> test message thing
- # [5] = pname023
- # [6] = test message thing
- unless match.nil?
- str = "<div class=\"chatwrap\"><div class=\"chattop\"><div class=\"chattime\">\n<img src=\"images/icons/#{match[5]}.png\" title=\"#{match[5]}\"><em>#{match[2]} #{match[3]}</em>\n</div></div><div class=\"chatmain\"><p>#{match[6]}</p></div><div class=\"chatbot\"></div>\n</div><br clear=\"all\">"
- $lines << str
- end
- end
- f.close
- end
- def write_file
- fstr = "#{$htmlhead}#{$lines.last(50).join}#{$htmlfoot}"
- $lines.clear #in case of loop
- f = File.new("chatbox.html", "w")
- f.print(fstr)
- f.close
- #If you need to cp or scp this file to your public directory, do this here.
- end
- def loop
- parse_file
- write_file
- end
- loop #see below
- #This file is written to be run with cron
- #If you want to just run this file once and have it work without cron, replace line 39 (loop) with the following
- #code and remove the comments
- #while true
- # loop
- # sleep(60) #sleep for one minute
- #end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement