Skip to content

Instantly share code, notes, and snippets.

@koorukuroo
Last active August 29, 2015 14:18
Show Gist options
  • Select an option

  • Save koorukuroo/7bbd59355af8557e309e to your computer and use it in GitHub Desktop.

Select an option

Save koorukuroo/7bbd59355af8557e309e to your computer and use it in GitHub Desktop.
Python Flask JSONP Method
def support_jsonp(f):
"""Wraps JSONified output for JSONP"""
@wraps(f)
def decorated_function(*args, **kwargs):
callback = request.args.get('callback', False)
if callback:
content = str(callback) + '(' + str(f(*args,**kwargs).data) + ')'
return current_app.response_class(content, mimetype='application/javascript')
else:
return f(*args, **kwargs)
return decorated_function
@support_jsonp
def test():
templist = [[1427673600000, 126.37],[1427414400000, 123.25],[1427328000000, 124.24],[1427241600000, 123.38],[1427155200000, 126.69],[1427068800000, 127.21],[1426809600000, 125.9],[1426723200000, 127.5],[1426636800000, 128.47],[1426550400000, 127.04],[1426464000000, 124.95],[1426204800000, 123.59],[1426118400000, 124.45],[1426032000000, 122.24],[1425945600000, 124.51],[1425859200000, 127.14],[1425600000000, 126.6],[1425513600000, 126.41],[1425427200000, 128.54],[1425340800000, 129.36],[1425254400000, 129.09]]
# text.append(str([int(date.strftime('%s')) * 1000, float(values[4])])+end)
return Response(response=result, status=200, mimetype="application/javascript")
@koorukuroo
Copy link
Author

listcontent[1:-1][::-1] for datetime sort

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment