Skip to content
Snippets Groups Projects
Commit f4f650af authored by Kenny Gao's avatar Kenny Gao
Browse files

JSON and cases fixed

JSON pretty printing set to off
JSON now looks like previous API
package turned into results
So JSON now has <result>: {<data>, <stamps>, <symbols>}
instead of package
Headers are now all lowercase
parent 0adef38d
No related branches found
No related tags found
1 merge request!2Order form
......@@ -5,10 +5,10 @@ def createXML(code, message):
header = 'metobs'
head = doc.createElement(header)
head.setAttribute('Status', 'Error')
head.setAttribute('Code', code)
head.setAttribute('Message', message)
head.setAttribute('Result', '0')
head.setAttribute('status', 'error')
head.setAttribute('code', code)
head.setAttribute('message', message)
head.setAttribute('num_results', '0')
doc.appendChild(head)
return doc.toprettyxml(indent=" ", encoding="utf-8")
......@@ -102,59 +102,59 @@ buoy_translation = {
resources = 'menodota buoy, and the aoss tower '
json_500 = {
'status': 'Error',
'status': 'error',
'code': '400',
'result': '0',
'message': 'Missing site or instrument parameter'
'num_results': '0',
'message': 'missing site or instrument parameter'
}
ascii_500 = '# Status: Error<br># Code: 400<br># Message: Missing site or instrument parameter<br># Results: 0'
ascii_500 = '# status: error<br># code: 400<br># message: missing site or instrument parameter<br># num_results: 0'
xml_500 = createXML('400', 'Missing site or instrument parameter')
xml_500 = createXML('400', 'missing site or instrument parameter')
json_404 = {
'status': 'Error',
'status': 'error',
'code': '404',
'result': '0',
'message': 'The resource could not be found - The current resources supported are the ' + resources
'num_results': '0',
'message': 'the resource could not be found - The current resources supported are the ' + resources
}
ascii_404 = '# Status: Error<br># Code: 404<br># Message: The resource could not be found - The current resources supported are the ' + resources + '<br># Results: 0'
ascii_404 = '# status: error<br># code: 404<br># message: the resource could not be found - The current resources supported are the ' + resources + '<br># num_results: 0'
xml_404 = createXML('404', 'The resource could not be found - The current resources supported are the ' + resources)
xml_404 = createXML('404', 'the resource could not be found - The current resources supported are the ' + resources)
json_stamp = {
'status': 'Error',
'status': 'error',
'code': '400',
'result': '0',
'message': 'Could not parse timestamp, check format'
'num_results': '0',
'message': 'could not parse timestamp, check format'
}
ascii_stamp = '# Status: Error<br># Code: 400<br># Message: Could not parse timestamp, check format<br># Results: 0'
ascii_stamp = '# status: error<br># code: 400<br># message: could not parse timestamp, check format<br># num_results: 0'
xml_stamp = createXML('400', 'Could not parse timestamp, check format')
xml_stamp = createXML('400', 'could not parse timestamp, check format')
json_mal = {
'status': 'Error',
'status': 'error',
'code': '400',
'result': '0',
'message': 'Server could not recognize if request is single-site or multi-site request'
'num_results': '0',
'message': 'server could not recognize if request is single-site or multi-site request'
}
ascii_mal = '# Status: Error<br># Code: 400<br># Message: Server could not recognize if request is single-site or multi-site request<br># Results: 0'
ascii_mal = '# status: error<br># code: 400<br># message: server could not recognize if request is single-site or multi-site request<br># num_results: 0'
xml_mal = createXML('400', 'Server could not recognize if request is single-site or multi-site request')
xml_mal = createXML('400', 'server could not recognize if request is single-site or multi-site request')
json_symbol = {
'status': 'Error',
'status': 'error',
'code': '400',
'result': '0',
'message': 'Server could not recognize symbol'
'num_results': '0',
'message': 'server could not recognize symbol'
}
ascii_symbol = '# Status: Error<br># Code: 400<br># Message: Server could not recognize symbol<br># Results: 0'
ascii_symbol = '# status: error<br># code: 400<br># message: server could not recognize symbol<br># num_results: 0'
xml_symbol = createXML('400', 'Server could not recognize symbol')
xml_symbol = createXML('400', 'server could not recognize symbol')
......
......@@ -190,16 +190,16 @@ def asciiReturn(frame, sep, symbols, site, inst, epoch):
dates = list(frame.columns.values)
output.write('# Status: Success<br># Code: 200<br># Message:<br>')
output.write('# Result: ' + str(len(dates)) + '<br>')
output.write('# status: success<br># code: 200<br># message:<br>')
output.write('# num_results: ' + str(len(dates)) + '<br>')
data = list(frame.iterrows())
if(not epoch):
output.write("# Fields: Site,Inst,YYYY-MM-DDTHH:MM:SSZ")
output.write("# fields: Site,Inst,YYYY-MM-DDTHH:MM:SSZ")
else:
output.write("# Fields: Site,Inst, " + epoch + " since epoch (1970-01-01 00:00:00)")
output.write("# fields: Site,Inst, " + epoch + " since epoch (1970-01-01 00:00:00)")
for symbol in symbols:
output.write(sep + symbol)
......@@ -218,10 +218,10 @@ def asciiReturn(frame, sep, symbols, site, inst, epoch):
def jsonReturn(frame, symbols, site, inst, jsonFormat, epoch):
output = {}
output['status'] = 'Success'
output['status'] = 'success'
output['message'] = ''
output['code'] = 200
output['num_result'] = str(len(list(frame.columns.values)))
output['num_results'] = str(len(list(frame.columns.values)))
package = {}
......@@ -263,7 +263,7 @@ def jsonReturn(frame, symbols, site, inst, jsonFormat, epoch):
package['data'] = dataList
output['package'] = package
output['results'] = package
return output
......@@ -277,10 +277,10 @@ def xmlReturn(site, inst, frame, symbols, sep, epoch):
timeStamps = list(frame.columns.values)
head = doc.createElement(header)
head.setAttribute('Status', 'Success')
head.setAttribute('Code', '200')
head.setAttribute('Message', '')
head.setAttribute('Result', str(len(timeStamps)))
head.setAttribute('status', 'success')
head.setAttribute('code', '200')
head.setAttribute('message', '')
head.setAttribute('num_results', str(len(timeStamps)))
head.setAttribute('seperator', sep)
doc.appendChild(head)
......
......@@ -120,8 +120,8 @@ def asciiReturn(frame, sep, symbols, epoch):
dates = list(frame.columns.values)
output.write('# Status: Success<br># Code: 200<br># Message:<br>')
output.write('# Result: ' + str(len(dates)) + '<br>')
output.write('# status: success<br># code: 200<br># message:<br>')
output.write('# num_results: ' + str(len(dates)) + '<br>')
data = list(frame.iterrows())
......@@ -147,7 +147,7 @@ def asciiReturn(frame, sep, symbols, epoch):
def jsonReturn(frame, symbols, jsonFormat, epoch):
output = {}
output['status'] = 'Success'
output['status'] = 'success'
output['message'] = ''
output['code'] = 200
......@@ -193,7 +193,7 @@ def jsonReturn(frame, symbols, jsonFormat, epoch):
package['data'] = dataList
output['package'] = package
output['results'] = package
return output
......@@ -209,10 +209,10 @@ def xmlReturn(frame, symbols, sep, epoch):
timeStamps = list(frame.columns.values)
head = doc.createElement(header)
head.setAttribute('Status', 'Success')
head.setAttribute('Code', '200')
head.setAttribute('Message', '')
head.setAttribute('Result', str(len(timeStamps)))
head.setAttribute('status', 'success')
head.setAttribute('code', '200')
head.setAttribute('message', '')
head.setAttribute('num_results', str(len(timeStamps)))
head.setAttribute('seperator', sep)
doc.appendChild(head)
......
......@@ -11,6 +11,7 @@ import pandas as pd
app = Flask(__name__)
app.config['SECRET_KEY'] = 'secret!'
app.config['JSONIFY_PRETTYPRINT_REGULAR'] = False
json = FlaskJSON(app)
def handleIntError(statusNo, fmt):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment