blob: 658ccafd97723123ad7925413406778192f87606 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
import os
import subprocess
from time import mktime
from datetime import date
from email.utils import parsedate
def file_last_modified(path):
git_log = f"git log --pretty=%aD {path}".split()
try:
ps = subprocess.Popen(git_log, stdout=subprocess.PIPE)
mod_time = subprocess.check_output(["tail", "-n1"],
stdin=ps.stdout)
except:
# File is not in the git log, no biggie, just blank the date
return None
# Git outputs in RFC2822 format
return parsedate(mod_time.decode('ascii').strip())
updates = {}
dirs = [x for x in os.listdir()
if os.path.isdir(x) and not x.startswith(".")
]
for top in dirs:
for root,_,files in os.walk(top):
for f in files:
if f.endswith(".html") or f.endswith(".txt") or f.endswith(".html!"):
path = os.path.join(root, f)
t = file_last_modified(path)
if t:
updates[path] = mktime(t)
print("<html>")
print("<body>")
print("<h3>LATEST POSTS</h3>")
print("<ul>")
for f, t in sorted(updates.items(),
key=lambda x: x[1],
reverse=True)[:10]:
#print(f, ctime(t), sep="\t")
if "latest.html" not in f:
print(f"\t<li><a href=/{f}>{f.split()[-1]}</a> - Published: {date.fromtimestamp(t)}</li>")
print("</ul>")
print("</body>")
print("</html>")
|