better doc, reloader

This commit is contained in:
boyska 2013-11-26 15:50:59 +01:00
parent d63eb48867
commit e287e70f56
2 changed files with 23 additions and 34 deletions

View file

@ -6,38 +6,35 @@ At the moment, it relies on some details that are specific of our radio (like
the directory/format of the continous recording). the directory/format of the continous recording).
Implementation details Implementation details
====================== ======================
It is based on bottle, to get a minimal framework. Rest APIs are offered It is based on bottle, to get a minimal framework. Simple APIs are offered
through it, and the static site uses them. through it, and the static site uses them.
Here are some examples of APIs usage
Create Create
-------- --------
JSON = { starttime-rec-1385231288390: 2013/11/23 19:32:49
'starttime-rec-1385231288390': '2013/11/23 19:32:49', endtime-rec-1385231288390: 2013/11/23 19:32:49
'endtime-rec-1385231288390': '2013/11/23 19:32:49', recid: rec-1385231288390
'recid': 'rec-1385231288390', name-rec-1385231288390: adasd
'name-rec-1385231288390': 'adasd', op: new
'op': 'new'
}
Update Update
------- -------
JSON = { starttime-rec-1385231288390: 2013/11/23 19:32:49
'starttime-rec-1385231288390': '2013/11/23 19:32:49', endtime-rec-1385231288390: 2013/11/23 19:32:49
'endtime-rec-1385231288390': '2013/11/23 19:32:49', recid: rec-1385231288390
'recid': 'rec-1385231288390', ### VALID REC ID name-rec-1385231288390: adasd
'name-rec-1385231288390': 'adasd', op: update
'op': 'update'
}
Delete Delete
------ ------
JSON = {
'recid': 'rec-1385231288390', ### VALID REC ID recid: rec-1385231288390
'op': 'delete' op: delete
}

View file

@ -6,17 +6,12 @@ from bottle import Bottle, request, static_file, redirect
from techrec import Rec, RecDB from techrec import Rec, RecDB
class RecServer: class RecServer:
def __init__(self,host="127.0.0.1", port=8000): def __init__(self):
self._host = host
self._port = port
self._app = Bottle() self._app = Bottle()
self._route() self._route()
self.db = RecDB() self.db = RecDB()
def start(self):
self._app.run(host=self._host, port=self._port, debug=True)
def _route(self): def _route(self):
### This is the API part of the app ### This is the API part of the app
@ -55,11 +50,11 @@ class RecServer:
print "Server:: Create request %s " % req print "Server:: Create request %s " % req
starttime = "" starttime = ""
if req["starttime-"+req["recid"]] != "": if req["starttime-" + req["recid"]] != "":
starttime = datetime.datetime.strptime( req["starttime-"+req["recid"]] , "%Y/%m/%d %H:%M:%S") starttime = datetime.datetime.strptime( req["starttime-"+req["recid"]] , "%Y/%m/%d %H:%M:%S")
endtime = datetime.datetime.now() endtime = datetime.datetime.now()
if req["endtime-"+req["recid"]] != "": if req["endtime-" + req["recid"]] != "":
endtime = datetime.datetime.strptime( req["endtime-"+req["recid"]] , "%Y/%m/%d %H:%M:%S") endtime = datetime.datetime.strptime( req["endtime-"+req["recid"]] , "%Y/%m/%d %H:%M:%S")
@ -165,7 +160,7 @@ class RecServer:
# @route('/help') # @route('/help')
def help(self): def help(self):
return " <h1>help</h1><hr/>\ return "<h1>help</h1><hr/>\
<h2>/get, /get/, /get/<recid> </h2>\ <h2>/get, /get/, /get/<recid> </h2>\
<h3>Get Info about rec identified by RECID </h3>\ <h3>Get Info about rec identified by RECID </h3>\
\ \
@ -177,9 +172,6 @@ class RecServer:
<h2>/update </h2>\ <h2>/update </h2>\
<h3>Not implemented.</h3>" <h3>Not implemented.</h3>"
"""
TESTs
"""
if __name__ == "__main__": if __name__ == "__main__":
c = RecServer(host="localhost") c = RecServer()
c.start() c._app.run(host="localhost", port="8000", debug=True, reloader=True)