Skip to content
Snippets Groups Projects
Verified Commit 20b1c7b6 authored by David Hoese's avatar David Hoese
Browse files

Add last_updated to instrument status API

parent adf5641f
No related branches found
No related tags found
No related merge requests found
import os
import json as builtin_json
import logging
from datetime import datetime
from urllib.request import urlopen, URLError
from flask import Flask, render_template, request, jsonify
......@@ -135,7 +136,6 @@ def _status_render(response, fmt):
def get_instrument_status(site, inst=None, fmt=None):
"""See `/api/status/` for more information."""
# defaults:
print(site, inst, fmt)
response = {
"name": site if inst is None else inst,
"short_name": "",
......@@ -143,6 +143,7 @@ def get_instrument_status(site, inst=None, fmt=None):
"status_code": 255,
"status_message": "",
}
mod_time = datetime.utcnow()
if fmt is None:
fmt = "html"
......@@ -171,6 +172,7 @@ def get_instrument_status(site, inst=None, fmt=None):
json_path = os.path.join(base_path, json_subpath)
try:
json_str = open(json_path, 'r').read()
mod_time = datetime.fromtimestamp(os.path.getmtime(json_path))
except FileNotFoundError:
response['status_message'] = "No status information found."
json_str = None
......@@ -180,6 +182,7 @@ def get_instrument_status(site, inst=None, fmt=None):
return _status_render(response, fmt)
json_dict = builtin_json.loads(json_str)
response['last_updated'] = mod_time.strftime("%Y-%m-%d %H:%M:%SZ")
response.update(json_dict)
return _status_render(response, fmt)
......
......@@ -133,6 +133,7 @@
<li>long_name: Long human-friendly name. For instruments this may include site name.</li>
<li>status_code: Integer code for current instrument status (see below)</li>
<li>status_message: Description and reason for current status</li>
<li>last_updated: YYYY-MM-DD HH:MM:SSZ</li>
</ul>
</p>
</div>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment