Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
MetObsAPI
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
MetObs
MetObsAPI
Commits
20b1c7b6
Verified
Commit
20b1c7b6
authored
Apr 19, 2019
by
David Hoese
Browse files
Options
Downloads
Patches
Plain Diff
Add last_updated to instrument status API
parent
adf5641f
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
metobsapi/server.py
+4
-1
4 additions, 1 deletion
metobsapi/server.py
metobsapi/templates/status_index.html
+1
-0
1 addition, 0 deletions
metobsapi/templates/status_index.html
with
5 additions
and
1 deletion
metobsapi/server.py
+
4
−
1
View file @
20b1c7b6
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
)
...
...
This diff is collapsed.
Click to expand it.
metobsapi/templates/status_index.html
+
1
−
0
View file @
20b1c7b6
...
...
@@ -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>
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment