From b91a817f11c0589f16d5596287731a88a0e9f941 Mon Sep 17 00:00:00 2001 From: Nathaniel Smith Date: Sat, 8 Nov 2014 20:09:28 -0500 Subject: [PATCH] sort by modified time, add user count --- scripts/userlist.hy | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/scripts/userlist.hy b/scripts/userlist.hy index 9ca81e5..b055be7 100644 --- a/scripts/userlist.hy +++ b/scripts/userlist.hy @@ -1,4 +1,5 @@ (import [os [listdir]]) +(import [os.path [getmtime]]) (import [datetime [datetime]]) ;; this script emits HTML on standard out that constitutes a user @@ -23,10 +24,23 @@ "(default :3)" "")))) -(def user-list (->> (listdir "/home") - sorted - (filter (fn [f] (and (not (= f "ubuntu")) (not (= f "poetry"))))) - (map dir->html) - (.join "\n"))) +(defn modify-time [username] + (getmtime (.format "/home/{}/public_html" username))) -(print (.format "generated at {}
" timestamp user-list)) + +(defn sort-user-list [usernames] + (apply sorted [usernames] {"key" modify-time})) + +(defn users [] (listdir "/home")) + +(def user-list (->> (users) + sort-user-list + reversed + (filter (fn [f] (and (not (= f "ubuntu")) (not (= f "poetry"))))) + (map dir->html) + (.join "\n"))) + +(print (.format "our esteemed users ({}) generated at {}
" + (len (users)) + timestamp + user-list))