summaryrefslogtreecommitdiffstats
path: root/update_latest.py
diff options
context:
space:
mode:
authormjfernez <mjf@mjfer.net>2023-11-22 13:55:19 -0500
committermjfernez <mjf@mjfer.net>2023-11-22 13:55:19 -0500
commit1c5025d54c3a8244fcbe818f96dea49e51054ba6 (patch)
tree22615506663bd546e430feea1c2ca3c4a58513b4 /update_latest.py
parentf602bb95e0b1160274bed0f125b8cfdedff3af96 (diff)
downloadsite-files-1c5025d54c3a8244fcbe818f96dea49e51054ba6.tar.gz
Update to new media directory syntax
Diffstat (limited to 'update_latest.py')
-rw-r--r--update_latest.py43
1 files changed, 43 insertions, 0 deletions
diff --git a/update_latest.py b/update_latest.py
new file mode 100644
index 0000000..160dc7c
--- /dev/null
+++ b/update_latest.py
@@ -0,0 +1,43 @@
+import os
+import subprocess
+from time import mktime, ctime
+from email.utils import parsedate
+
+def file_last_modified(path):
+ git_time = f"git log -n1 --pretty=%aD {path}".split()
+ try:
+ mod_time = subprocess.check_output(git_time)
+ 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"):
+ path = os.path.join(root, f)
+ t = file_last_modified(path)
+ if t:
+ updates[path] = mktime(t)
+print("<html>")
+print("<body>")
+print("<h3>LATEST CHANGES</h3>")
+print("<ul>")
+for f, t in sorted(updates.items(),
+ key=lambda x: x[1],
+ reverse=True)[:10]:
+ #print(f, ctime(t), sep="\t")
+ print(f"\t<li><a href={f}>{f.split()[-1]}</a> - Updated: {ctime(t)}</li>")
+
+print("</ul>")
+print("</body>")
+print("</html>")
+