eristoddle
6/7/2012 - 3:19 PM

Parse files with mod date in folders and output html

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")