Skip to content

Commit

Permalink
add serverlist JSON operation
Browse files Browse the repository at this point in the history
  • Loading branch information
cl4u2 committed Dec 1, 2012
1 parent 11c0c7e commit 0722a2b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
4 changes: 4 additions & 0 deletions JsonAPI.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ retrieve at least <nresults> results, but no more than <nresults>
URL: /json.cgi?op=whatsnew&nresults=<nresults>
NOTES: nresults default is 200

Operation: serverlist
Description: return the list of found servers
URL: /json.cgi?op=serverlist

== Search Results Format ==

{
Expand Down
15 changes: 15 additions & 0 deletions dbmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
9 changes: 9 additions & 0 deletions jsonif.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 0722a2b

Please sign in to comment.