summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomek Dubrownik <t.dubrownik@gmail.com>2012-01-27 10:19:04 +0100
committerTomek Dubrownik <t.dubrownik@gmail.com>2012-01-27 10:19:04 +0100
commitc8803e9b3840c600dbee2b35a1dc7ad31d98d305 (patch)
tree7b43163d7f762c3a464b9dc1e749f1d143eb32ad
parentdbe9db0e4ace032734256f90773c039f590dfcba (diff)
downloadcheckinator-c8803e9b3840c600dbee2b35a1dc7ad31d98d305.tar.gz
checkinator-c8803e9b3840c600dbee2b35a1dc7ad31d98d305.tar.bz2
checkinator-c8803e9b3840c600dbee2b35a1dc7ad31d98d305.zip
bot-friendly json call
-rw-r--r--at.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/at.py b/at.py
index 4a3b09c..a633ecb 100644
--- a/at.py
+++ b/at.py
@@ -4,6 +4,7 @@ import logging
import sqlite3
import threading
import traceback
+import json
from datetime import datetime
from wsgiref import simple_server
from pesto import Response, dispatcher_app
@@ -150,6 +151,25 @@ class DnsmasqUpdater(Updater):
@dispatcher.match('/', 'GET')
@render('main.html')
+def main_view(request):
+ return now_at(request)
+
+@dispatcher.match('/api', 'GET')
+def list_all(request):
+ result = now_at(request)
+ def prettify_user((user, atime)):
+ return {
+ 'login': user.login,
+ 'timestamp': atime,
+ 'pretty_time': strfts(atime),
+ 'url': user.url,
+ }
+ result['users'] = map(prettify_user, result['users'])
+ result['unknown'] = len(result['unknown'])
+ del result['login']
+ return Response(json.dumps(result))
+
+
def now_at(request):
devices = updater.get_active_devices()
device_infos = list(get_device_infos(conn, devices.keys()))