-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetData.py
21 lines (19 loc) · 811 Bytes
/
getData.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
from flask import Blueprint, jsonify
from models import Data
from app import cache
getdata_bp = Blueprint('getdata_bp', __name__)
@getdata_bp.route("/getdata/<int:device_fk_id>", methods=['GET'])
@cache.cached(timeout=120, query_string=True)
def getdata(device_fk_id):
try:
data = Data.query.filter_by(device_fk_id=device_fk_id).order_by(
Data.time_stamp.desc()).first()
result = {'device_fk_id': data.device_fk_id, 'latitude': data.latitude, 'longitude': data.longitude,
'time_stamp': data.time_stamp.strftime('%Y-%m-%dT%H:%M:%SZ'), 'sts': data.sts, 'speed': data.speed}
return jsonify(result)
except Exception as e:
response = {
"errorCode": "500",
"errorMessage": str(e)
}
return jsonify(response)