diff --git a/scripts/generate_home_page.sh b/scripts/generate_home_page.sh index 1a591cf..5d1935b 100755 --- a/scripts/generate_home_page.sh +++ b/scripts/generate_home_page.sh @@ -4,15 +4,10 @@ export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/ga source /var/local/venvs/tildetown/bin/activate -stats=/usr/local/bin/generate_stats +stats=/usr/bin/stats template=/var/www/tilde.town/template.index.html mustache=/var/local/tildetown/scripts/mustache.hy output_path=/var/www/tilde.town/index.html -# hello from datagrok -# -# generate_stats was breaking and outputting no lines. i dunno how to fix that, -# but i can un-disaappear the homepage by saying "output empty json if broken" -# -# generate_stats | hy $mustache $template > $output_path ($stats || echo '{}') | hy $mustache $template > $output_path +deactivate diff --git a/scripts/stats b/scripts/stats new file mode 100755 index 0000000..29e4b58 --- /dev/null +++ b/scripts/stats @@ -0,0 +1,8 @@ +#!/bin/bash + +cd /var/local + +source venvs/tildetown/bin/activate +output=$(python tildetown/tildetown-py/stats.py) +deactivate +echo $output diff --git a/scripts/town_stats.hy b/scripts/town_stats.hy deleted file mode 100644 index 43a34e4..0000000 --- a/scripts/town_stats.hy +++ /dev/null @@ -1,65 +0,0 @@ -(import [json [dumps]]) -(import [os [listdir]]) -(import [os.path [getmtime]]) -(import [datetime [datetime]]) - -(import [sh [find facter]]) - -;; this script emits json on standard out that has information about tilde.town -;; users. It denotes who has not updated their page from the default. It also -;; reports the time this script was run. The user list is sorted by public_html update time. - -(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 default? [username] - (= default-html (slurp (.format "/home/{}/public_html/index.html" username)))) - -(defn bounded-find [path] - ;; find might return 1 but still have worked fine (because of dirs it can't - ;; go into) - (apply find [path "-maxdepth" "3"] {"_ok_code" [0 1]})) - -(defn guarded-mtime [filename] - (let [[path (.rstrip filename)]] - (try - (getmtime path) - (catch [e Exception] - 0)))) - -(defn modify-time [username] - (->> (.format "/home/{}/public_html" username) - bounded-find - (map guarded-mtime) - list - max)) - -(defn sort-user-list [usernames] - (apply sorted [usernames] {"key" modify-time})) - -(defn user-generator [] (->> (listdir "/home") - (filter (fn [f] (and (not (= f "ubuntu")) (not (= f "poetry"))))))) - -(if (= __name__ "__main__") - (let [[all_users (->> (user-generator) - sort-user-list - reversed - (map (fn [un] {"username" un - "default" (default? un)})) - list)] - [live_users (-> (filter (fn [u] (not (get u "default"))) all_users) - list)] - [data {"all_users" all_users - "live_users" live_users - "active_user_count" (-> (. (facter "active_user_count") stdout) - .strip - int) - "generated_at" (.strftime (.now datetime) "%Y-%m-%d %H:%M:%S") - "num_users" (len all_users) - "num_live_users" (len live_users)}]] - (print (dumps data))))