This repository has been archived on 2019-12-12. You can view files and clone it, but cannot push or open issues/pull-requests.
tildetown-scripts/scripts/userlist.hy

47 lines
1.4 KiB
Hy

(import [os [listdir]])
(import [os.path [getmtime]])
(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]
(try
(.read (apply open [filename "r"] {"encoding" "utf-8"}))
(catch [e Exception]
"")))
(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" username)))]]
(.format "<li><a href=\"http://tilde.town/~{}\">{}</a> {}</li>"
username username
(if default
"(default :3)"
""))))
(defn modify-time [username]
(getmtime (.format "/home/{}/public_html" username)))
(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 ({}) <sub>generated at {}</sub><br><ul>{}</ul>"
(len (users))
timestamp
user-list))