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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
MetObs
MetObsAPI
Commits
ac12d2d4
Verified
Commit
ac12d2d4
authored
6 years ago
by
David Hoese
Browse files
Options
Downloads
Patches
Plain Diff
Fix status API to return HTML when no information is found
parent
23259af5
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
metobsapi/server.py
+19
-5
19 additions, 5 deletions
metobsapi/server.py
with
19 additions
and
5 deletions
metobsapi/server.py
+
19
−
5
View file @
ac12d2d4
...
...
@@ -112,6 +112,22 @@ def status_index():
return
render_template
(
'
status_index.html
'
)
def
_status_dict_to_html
(
response
):
items
=
"
<br>
\n
"
.
join
(
"
{}: {}
"
.
format
(
k
,
v
)
for
k
,
v
in
sorted
(
response
.
items
()))
return
"""
<html>
<body>
{}
</body>
</html>
"""
.
format
(
items
)
def
_status_render
(
response
,
fmt
):
if
fmt
==
'
json
'
:
return
jsonify
(
response
)
else
:
return
_status_dict_to_html
(
response
)
@app.route
(
'
/api/status/<site>/<inst>.<fmt>
'
,
methods
=
[
'
GET
'
])
@app.route
(
'
/api/status/<site>/<inst>
'
,
methods
=
[
'
GET
'
])
@app.route
(
'
/api/status/<site>.<fmt>
'
,
methods
=
[
'
GET
'
])
...
...
@@ -119,6 +135,7 @@ def status_index():
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
"
:
""
,
...
...
@@ -160,14 +177,11 @@ def get_instrument_status(site, inst=None, fmt=None):
if
json_str
is
None
:
# exit out early, we don't know what this is
return
jsonify
(
response
)
return
_status_render
(
response
,
fmt
)
json_dict
=
builtin_json
.
loads
(
json_str
)
response
.
update
(
json_dict
)
if
fmt
==
'
json
'
:
return
jsonify
(
response
)
else
:
return
"
<br>
"
.
join
(
"
{}: {}
"
.
format
(
k
,
v
)
for
k
,
v
in
sorted
(
response
.
items
()))
return
_status_render
(
response
,
fmt
)
if
__name__
==
'
__main__
'
:
...
...
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