From 0722a2b26870abca8f212e13bf6bfade3b5fe223 Mon Sep 17 00:00:00 2001 From: Clauz Date: Sun, 2 Dec 2012 00:24:23 +0100 Subject: [PATCH] add serverlist JSON operation --- JsonAPI.txt | 4 ++++ dbmanager.py | 15 +++++++++++++++ jsonif.py | 9 +++++++++ 3 files changed, 28 insertions(+) diff --git a/JsonAPI.txt b/JsonAPI.txt index 50fece4..ad0bc9c 100644 --- a/JsonAPI.txt +++ b/JsonAPI.txt @@ -37,6 +37,10 @@ retrieve at least results, but no more than URL: /json.cgi?op=whatsnew&nresults= NOTES: nresults default is 200 +Operation: serverlist +Description: return the list of found servers +URL: /json.cgi?op=serverlist + == Search Results Format == { diff --git a/dbmanager.py b/dbmanager.py index fe03ad6..4189668 100644 --- a/dbmanager.py +++ b/dbmanager.py @@ -400,6 +400,21 @@ def likequery(self, query, limit=3): cursor.close() return qr + def __getServerList(self, cursor, timediff=TIMEDIFF): + selectionstring = """ + SELECT resources.server + FROM resources + WHERE UNIX_TIMESTAMP(resources.timestamp) >= UNIX_TIMESTAMP(NOW()) - %d + GROUP BY resources.server""" % timediff + cursor.execute(selectionstring) + r = [e[0] for e in cursor.fetchall()] + return r + def getServerList(self): + qr = QueryResultS() + cursor = self.conn.cursor() + return self.__getServerList(cursor) + + if __name__ == "__main__": rs = ResourceStorer('localhost','ninuu','ciaociao','ninuxuu') diff --git a/jsonif.py b/jsonif.py index cf28151..b4fcb32 100644 --- a/jsonif.py +++ b/jsonif.py @@ -274,3 +274,12 @@ def whatsnew(self, request): return response + def serverlist(self, request): + "return the list of servers indexed by the search engine" + try: + res = self.qm.getServerList() + response = JsonResponse(RESPONSE_OK, None, {'result': res}) + except Exception, e: + response = JsonResponse(RESPONSE_SERVERERROR, str(e)) + return response +