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

33 lines
1.1 KiB
Hy
Raw Normal View History

2014-10-15 05:07:15 +00:00
(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]
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)"
""))))
(def user-list (->> (listdir "/home")
sorted
2014-11-09 00:35:01 +00:00
(filter (fn [f] (and (not (= f "ubuntu")) (not (= f "poetry")))))
2014-10-15 05:07:15 +00:00
(map dir->html)
(.join "\n")))
2014-10-15 20:31:00 +00:00
(print (.format "<sub>generated at {}</sub><br><ul>{}</ul>" timestamp user-list))