Last active
August 29, 2015 14:23
-
-
Save sbp/60b664d5b52fdc21401e to your computer and use it in GitHub Desktop.
Simple log renderer
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
#!/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("&", "&").replace("<", "<") | |
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