update scripts for new /usr/local location

master
Michael F. Lamb 2015-10-20 21:49:20 +00:00
parent 37768ae726
commit cb142fe9b8
4 changed files with 29 additions and 32 deletions

View File

@ -1,2 +0,0 @@
#!/bin/bash
who | cut -d' ' -f1 | sort -u | wc -l | xargs echo "active_user_count=" | sed 's/ //'

View File

@ -1,13 +1,18 @@
#!/bin/bash #!/bin/bash
# Feed JSON/tdp output from "stats" into mustache template to generate
# tilde.town homepage. Invoke periodically from crontab.
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
source /var/local/venvs/tildetown/bin/activate template=/usr/local/tildetown-scripts/tildetown/templates/frontpage.html
mustache=/usr/local/tildetown-scripts/tildetown/mustache.py
stats=/usr/bin/stats input_path=/var/www/tilde.town/tilde.json
template=/var/local/tildetown/templates/frontpage.html
mustache=/var/local/tildetown/scripts/mustache.hy
output_path=/var/www/tilde.town/index.html output_path=/var/www/tilde.town/index.html
($stats || echo '{}') | hy $mustache $template > $output_path if [ ! -f "$input_path" ]; then
deactivate print "homepage generation needs missing $input_path"
exit 1
fi
exec /usr/local/virtualenvs/tildetown/bin/python "$mustache" "$template" < "$input_path" > "$output_path"

View File

@ -1,8 +1,6 @@
#!/bin/bash #!/bin/sh
# run stats.py in the appropriate virtualenv.
cd /var/local #
# invoke periodically from crontab and direct the output to
source venvs/tildetown/bin/activate # /var/www/tilde.town/tilde.json
output=$(python tildetown/tildetown-py/stats.py) exec /usr/local/virtualenvs/tildetown/bin/python /usr/local/tildetown-scripts/tildetown/stats.py
deactivate
echo $output

View File

@ -1,6 +1,6 @@
#!/usr/local/bin/python3 #!/usr/local/bin/python3
# tdp.py - tilde data in tilde data protocol format. # stats.py - tilde data in tilde data protocol format.
# Copyright 2015 Michael F. Lamb <http://datagrok.org> # Copyright 2015 Michael F. Lamb <http://datagrok.org>
# License: GPLv3+ # License: GPLv3+
@ -14,11 +14,10 @@ It is a JSON structure of the form:
'name': (string) the name of the server. 'name': (string) the name of the server.
'url': (string) the URL of the server. 'url': (string) the URL of the server.
'signup_url': (string) the URL of a page describing the process required to request an account on the server. 'signup_url': (string) the URL of a page describing the process required to request an account on the server.
'user_count': (number) the number of users currently registered on the server.
'want_users': (boolean) whether the server is currently accepting new user requests. 'want_users': (boolean) whether the server is currently accepting new user requests.
'admin_email': (string) the email address of the primary server administrator. 'admin_email': (string) the email address of the primary server administrator.
'description': (string) a free-form description for the server. 'description': (string) a free-form description for the server.
'users': [ (array) an array of users on the server. 'users': [ (array) an array of users on the server, sorted by last activity time
{ {
'username': (string) the username of the user. 'username': (string) the username of the user.
'title': (string) the HTML title of the users index.html page. 'title': (string) the HTML title of the users index.html page.
@ -26,30 +25,24 @@ It is a JSON structure of the form:
}, },
... ...
] ]
'user_count': (number) the number of users currently registered on the server.
} }
We also overload this with the preexisting data format we were using in We also overload this with some data we were using in the previous version of
/var/local/tildetown/tildetown-py/stats.py, which is of the form: stats.py, which is of the form:
{ {
'all_users': [ (array) of users on the server. 'users': [ (array) of users on the server.
{ {
'username': (string) the username of the user.
'default': (boolean) Is the user still using their unmodified default index.html? 'default': (boolean) Is the user still using their unmodified default index.html?
'favicon': (string) a url to an image representing the user 'favicon': (string) a url to an image representing the user
}, },
... ...
] ]
'num_users': (number) count of all_users 'live_user_count': (number) count of live users (those who have changed their index.html)
'live_users': [ (array) an array of live users, same format as all_users. Users may appear in both arrays.
...
],
'num_live_users': (number) count of live users
'active_user_count': (number) count of currently logged in users 'active_user_count': (number) count of currently logged in users
'generated_at': (string) the time this JSON was generated in '%Y-%m-%d %H:%M:%S' format. 'generated_at': (string) the time this JSON was generated in '%Y-%m-%d %H:%M:%S' format.
'generated_at_msec': (number) the time this JSON was generated, in milliseconds since the epoch. 'generated_at_msec': (number) the time this JSON was generated, in milliseconds since the epoch.
'site_name': (same as 'name' above)
'site_url': (same as 'url' above)
'uptime': (string) output of `uptime -p` 'uptime': (string) output of `uptime -p`
} }
@ -148,7 +141,10 @@ def tdp_user(username, homedir):
def tdp(): def tdp():
now = datetime.datetime.now() now = datetime.datetime.now()
users = [tdp_user(u, h) for u, h in get_users()] users = sorted(
(tdp_user(u, h) for u, h in get_users()),
key=lambda x:x['mtime'],
reverse=True)
# TDP format data # TDP format data
data = { data = {