aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMitja Felicijan <mitja.felicijan@gmail.com>2012-09-26 20:47:09 +0200
committerMitja Felicijan <mitja.felicijan@gmail.com>2012-09-26 20:47:09 +0200
commit8d462c1a4f0938b1c1b1e750f467270e50b4aa74 (patch)
tree3d4f836e69582d1cc7ea8f120b79278b58879f6f
parentfdb08c33a6af9c64c7875e23d01b4b71770ac6d7 (diff)
downloadnanocloudlogger-8d462c1a4f0938b1c1b1e750f467270e50b4aa74.tar.gz
nanocloudlogger-8d462c1a4f0938b1c1b1e750f467270e50b4aa74.zip
Set and Get methods are now available.
-rwxr-xr-xsrc/loggergae/api.py75
1 files changed, 64 insertions, 11 deletions
diff --git a/src/loggergae/api.py b/src/loggergae/api.py
index 9505fcf..e7ff03a 100755
--- a/src/loggergae/api.py
+++ b/src/loggergae/api.py
@@ -1,28 +1,81 @@
-import cgi
-import datetime
import webapp2
-
+import simplejson as json
from google.appengine.ext import db
class Feed(db.Model):
- secret = db.StringProperty()
- content = db.StringProperty(multiline=True)
- date = db.DateTimeProperty(auto_now_add=True)
+ stream = db.StringProperty()
+ input = db.StringProperty(multiline=True)
+ data = db.StringProperty(multiline=True)
+ datetime = db.DateTimeProperty(auto_now_add=True)
class MainPage(webapp2.RequestHandler):
def get(self):
self.response.out.write('main page')
-class Stream(webapp2.RequestHandler):
+
+
+class StreamGet(webapp2.RequestHandler):
+ def get(self):
+ response = []
+
+ if self.request.get('limit') <> '': limit = 'limit ' + self.request.get('limit')
+ else: limit = ''
+
+ feed = db.GqlQuery('select * from Feed where stream=:1 order by datetime desc ' + limit, self.request.get('stream'))
+
+ if self.request.get('lastid') <> '':
+ for entry in feed:
+ if int(self.request.get('lastid')) < entry.key().id():
+ response.append({'id': entry.key().id(),
+ 'input': str(entry.input),
+ 'data': str(entry.data),
+ 'datetime': str(entry.datetime)
+ })
+ else:
+ for entry in feed:
+ response.append({'id': entry.key().id(),
+ 'input': str(entry.input),
+ 'data': str(entry.data),
+ 'datetime': str(entry.datetime)
+ })
+
+ if self.request.get('format') == 'csv':
+ self.response.headers['Content-Type'] = 'plain/text'
+ for item in response:
+ self.response.out.write(str(item['id']) + ',')
+ self.response.out.write(str(item['datetime']) + ',')
+ self.response.out.write(str(item['input']) + ',')
+ self.response.out.write(str(item['data']) + '\n')
+ else:
+ self.response.headers['Content-Type'] = 'application/json'
+ self.response.out.write(json.dumps(response, separators=(',',':')))
+ def post(self):
+ self.error(405)
+ self.response.out.write('405 Method Not Allowed')
+
+class StreamSet(webapp2.RequestHandler):
def get(self):
- self.response.out.write('stream get')
+ self.error(405)
+ self.response.out.write('405 Method Not Allowed')
def post(self):
- self.response.out.write('stream post')
+ for input in self.request.arguments():
+ if (str(input) <> 'format' and str(input) <> 'stream'):
+ feed = Feed()
+ feed.stream = str(self.request.get('stream'))
+ feed.data = self.request.get(input)
+ feed.input = str(input)
+ feed.put()
+ if self.request.get('format') == 'csv':
+ self.response.headers['Content-Type'] = 'plain/text'
+ self.response.out.write('status: ok')
+ else:
+ self.response.headers['Content-Type'] = 'application/json'
+ self.response.out.write(json.dumps({'status' : 'ok'}, separators=(',',':')))
app = webapp2.WSGIApplication([
('/api', MainPage),
- ('/api/get', Stream),
- ('/api/set', Stream),
+ ('/api/get', StreamGet),
+ ('/api/set', StreamSet),
('/', MainPage)
], debug=True) \ No newline at end of file