From 85a22b5329afa661f5a5167b3bbda3280983e471 Mon Sep 17 00:00:00 2001 From: Nathaniel Smith Date: Wed, 15 Oct 2014 01:07:15 -0400 Subject: [PATCH] first pass on userlist --- scripts/userlist.hy | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 scripts/userlist.hy diff --git a/scripts/userlist.hy b/scripts/userlist.hy new file mode 100644 index 0000000..f98147d --- /dev/null +++ b/scripts/userlist.hy @@ -0,0 +1,29 @@ +(import [os [listdir]]) +(import [datetime [datetime]]) + +;; this script emits HTML on standard out that constitutes a user +;; list. It denotes who has not updated their page from the +;; default. It also reports the time this script was run. + +(def timestamp (.strftime (.now datetime) "%Y-%m-%d %H:%M:%S")) + +(defn slurp [filename] + (.read (open filename "r"))) + +(def default-html (slurp "/etc/skel/public_html/index.html")) + +(defn dir->html [username] + (let [[default (= default-html (slurp (.format "/home/{}/public_html/index.html" dirname)))]] + (.format "
  • {} {}
  • " + username username + (if default + "(default :3)" + "")))) + +(def user-list (->> (listdir "/home") + sorted + (filter (fn [f] (not (= f "ubuntu")))) + (map dir->html) + (.join "\n"))) + +(print (.format "generated at {}
    {}" timestamp user-list))