Skip to content

Instantly share code, notes, and snippets.

@sbp
Last active August 29, 2015 14:23
Show Gist options
  • Save sbp/60b664d5b52fdc21401e to your computer and use it in GitHub Desktop.
Save sbp/60b664d5b52fdc21401e to your computer and use it in GitHub Desktop.
Simple log renderer
#!/usr/bin/env python3
import codecs
import re
import sys
sys.stdout = codecs.getwriter("utf-8")(sys.stdout.detach())
link = r'((ftp|https?)://([^\s<>"\'\[\]),;:.&]|&(?![gl]t;)|[\[\]),;:.](?! ))+)'
print("Content-Type: text/html; charset=utf-8")
print("")
with open("LOG", encoding="utf-8") as log:
previous = 0
ptext = ""
for line in log:
unixtime = int(line[:10])
if (previous > 0) and ((unixtime - previous) > 90):
print("<br><br>")
elif not (ptext[-1:] in ".?!"):
print("<br><br>")
text = line[11:].replace("&", "&amp;").replace("<", "&lt;")
text = re.sub(link, '<a href="\g<0>">\g<0></a>', text)
text = text.rstrip("\n")
print(text)
previous = unixtime
ptext = text
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment