42 lines
1.3 KiB
Python
42 lines
1.3 KiB
Python
import logging
|
|
import werkzeug
|
|
from flask import request, Response
|
|
import json
|
|
import datetime
|
|
|
|
class Entry(object):
|
|
def __init__(self, d):
|
|
self.ts = d['timestamp']
|
|
self.freq = d['frequency']
|
|
def __repr__(self):
|
|
return self.__str__()
|
|
def __str__(self):
|
|
return "<ts:{}, f:{}>".format(self.ts, self.freq)
|
|
|
|
def insert(**args):
|
|
try:
|
|
entryListJSON = request.json
|
|
logging.info("JSON Body: {}".format(entryListJSON))
|
|
entryList = [ Entry(x) for x in entryListJSON ]
|
|
logging.info("EntryList: {}".format(entryList))
|
|
return Response("", status=201)
|
|
except KeyError as e:
|
|
raise werkzeug.exceptions.InternalServerError("Key Error: {}".format(e))
|
|
|
|
|
|
def get(start, stop, token_info=None, location=None):
|
|
logging.info("Token: {}".format(token_info))
|
|
if 'read/mainscnt/entries' not in token_info['x-scope']:
|
|
raise werkzeug.exceptions.Forbidden()
|
|
LIMITS_PREFIX = 'mainscnt/entries/'
|
|
limit = 0
|
|
if ('x-limits' in token_info) and (token_info['x-limits'].startswith(LIMITS_PREFIX)):
|
|
limit = int(token_info['x-limits'][len(LIMITS_PREFIX):])
|
|
res = [
|
|
{
|
|
'timestamp': datetime.datetime.now(),
|
|
'frequency': 50.0,
|
|
'maxentries': limit
|
|
}
|
|
]
|
|
return res |