|
|
@ -7,7 +7,7 @@ from datetime import datetime
|
|
|
|
|
|
|
|
|
|
|
|
from fields import DESCRIPTION
|
|
|
|
from fields import DESCRIPTION
|
|
|
|
|
|
|
|
|
|
|
|
def _render_current(data, for_day="current"):
|
|
|
|
def _render_current(data, for_day="current", already_seen=[]):
|
|
|
|
"Converts data into prometheus style format"
|
|
|
|
"Converts data into prometheus style format"
|
|
|
|
|
|
|
|
|
|
|
|
output = []
|
|
|
|
output = []
|
|
|
@ -41,8 +41,11 @@ def _render_current(data, for_day="current"):
|
|
|
|
description = f", description=\"{value}\""
|
|
|
|
description = f", description=\"{value}\""
|
|
|
|
value = "1"
|
|
|
|
value = "1"
|
|
|
|
|
|
|
|
|
|
|
|
output.append(f"# HELP {name} {help}\n"
|
|
|
|
if name not in already_seen:
|
|
|
|
f"{name}{{forecast=\"{for_day}\"{description}}} {value}")
|
|
|
|
output.append(f"# HELP {name} {help}")
|
|
|
|
|
|
|
|
already_seen.append(name)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
output.append(f"{name}{{forecast=\"{for_day}\"{description}}} {value}")
|
|
|
|
|
|
|
|
|
|
|
|
return "\n".join(output)+"\n"
|
|
|
|
return "\n".join(output)+"\n"
|
|
|
|
|
|
|
|
|
|
|
@ -57,8 +60,10 @@ def render_prometheus(data):
|
|
|
|
and return it as string.
|
|
|
|
and return it as string.
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
answer = _render_current(data["current_condition"][0])
|
|
|
|
already_seen = []
|
|
|
|
|
|
|
|
answer = _render_current(
|
|
|
|
|
|
|
|
data["current_condition"][0], already_seen=already_seen)
|
|
|
|
for i in range(3):
|
|
|
|
for i in range(3):
|
|
|
|
data2 = data["weather"][i]
|
|
|
|
answer += _render_current(
|
|
|
|
answer += _render_current(data2, for_day="%sd" % i)
|
|
|
|
data["weather"][i], for_day="%sd" % i, already_seen=already_seen)
|
|
|
|
return answer
|
|
|
|
return answer
|
|
|
|