Spaces:
Sleeping
Sleeping
File size: 964 Bytes
dcb132a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
import datetime
import flask
pingBP = flask.Blueprint("ping", __name__)
@pingBP.route("/api/v1/ping")
async def pingFunction():
date = flask.request.args.get("date")
if date:
send = datetime.datetime.strptime(date, "%Y-%m-%dT%H:%M:%S.%fZ")
receive = datetime.datetime.utcnow()
diff = receive - send
return {
"code": 200,
"content": {
"ping": diff.total_seconds(),
"send_time": send.strftime("%Y-%m-%dT%H:%M:%S.%fZ"),
"receive_time": receive.strftime("%Y-%m-%dT%H:%M:%S.%fZ"),
},
"message": "You have a one way ping of %s seconds" % (diff.total_seconds()),
}
else:
return (
{
"code": 200,
"content": "Pong",
"message": "Ping received.",
"success": True,
},
200,
)
|