Skip to content

Instantly share code, notes, and snippets.

@eristoddle
Created June 7, 2012 15:19
Show Gist options
  • Save eristoddle/2889366 to your computer and use it in GitHub Desktop.
Save eristoddle/2889366 to your computer and use it in GitHub Desktop.
Parse files with mod date in folders and output html
"""
I use this for files I save in Epistle for Android when I save links from my6sense. Yes, a very specific use case, but it might be useful to others.
"""
import os, time, webbrowser, glob
l = [(os.stat(i).st_mtime, i) for i in glob.glob('*txt')]
l.sort()
files = [i[1] for i in l]
files.reverse()
html_file = []
for file in files:
with open(file) as f:
try:
content = f.readlines()
title = content[0]
link = content[len(content) - 3]
(mode, ino, dev, nlink, uid, gid, size, atime, mtime, ctime) = os.stat(file)
html_file.append("<strong>" + time.ctime(mtime) + "</strong> : ")
html_file.append('<a href="' + link + '">' + title + '</a><br />')
except:
html_file.append("<p>Error with " + file + "</p>")
html_file.append("<hr />")
out_file = open("results.html", "w")
out_file.write("".join(html_file))
webbrowser.open_new_tab("results.html")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment