2014-10-15 05:07:15 +00:00
|
|
|
(import [os [listdir]])
|
2014-11-09 01:09:28 +00:00
|
|
|
(import [os.path [getmtime]])
|
2014-10-15 05:07:15 +00:00
|
|
|
(import [datetime [datetime]])
|
|
|
|
|
2014-12-29 02:46:07 +00:00
|
|
|
(import [sh [find]])
|
|
|
|
|
2014-10-15 05:07:15 +00:00
|
|
|
;; 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]
|
2014-11-09 00:35:01 +00:00
|
|
|
(try
|
|
|
|
(.read (apply open [filename "r"] {"encoding" "utf-8"}))
|
|
|
|
(catch [e Exception]
|
|
|
|
"")))
|
2014-10-15 05:07:15 +00:00
|
|
|
|
|
|
|
(def default-html (slurp "/etc/skel/public_html/index.html"))
|
|
|
|
|
|
|
|
(defn dir->html [username]
|
2014-10-15 05:18:32 +00:00
|
|
|
(let [[default (= default-html (slurp (.format "/home/{}/public_html/index.html" username)))]]
|
2014-10-15 05:07:15 +00:00
|
|
|
(.format "<li><a href=\"http://tilde.town/~{}\">{}</a> {}</li>"
|
|
|
|
username username
|
|
|
|
(if default
|
|
|
|
"(default :3)"
|
|
|
|
""))))
|
|
|
|
|
2014-11-09 01:09:28 +00:00
|
|
|
(defn modify-time [username]
|
2014-12-29 02:46:07 +00:00
|
|
|
(->> (.format "/home/{}/public_html" username)
|
|
|
|
find
|
|
|
|
(map (fn [filename] (getmtime (.rstrip filename))))
|
|
|
|
list
|
|
|
|
max))
|
2014-11-09 01:09:28 +00:00
|
|
|
|
|
|
|
(defn sort-user-list [usernames]
|
|
|
|
(apply sorted [usernames] {"key" modify-time}))
|
|
|
|
|
2014-11-09 01:16:11 +00:00
|
|
|
(defn user-generator [] (->> (listdir "/home")
|
2014-12-29 02:49:15 +00:00
|
|
|
(filter (fn [f] (and (not (= f "ubuntu")) (not (= f "poetry")))))
|
|
|
|
list))
|
2014-11-09 01:09:28 +00:00
|
|
|
|
2014-11-09 01:15:06 +00:00
|
|
|
(def user-list (->> (user-generator)
|
2014-11-09 01:09:28 +00:00
|
|
|
sort-user-list
|
|
|
|
reversed
|
|
|
|
(map dir->html)
|
|
|
|
(.join "\n")))
|
|
|
|
|
2014-11-09 01:13:12 +00:00
|
|
|
(print (.format "our esteemed users ({})<br> <sub>generated at {}</sub><br><ul>{}</ul>"
|
2014-11-09 01:15:06 +00:00
|
|
|
(len (user-generator))
|
2014-11-09 01:09:28 +00:00
|
|
|
timestamp
|
|
|
|
user-list))
|