Skip to content

Commit

Permalink
prometheus module: use py3.safe_format()
Browse files Browse the repository at this point in the history
  • Loading branch information
bbusse committed Jun 22, 2023
1 parent 5eb4248 commit 8a9fc40
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions py3status/modules/prometheus.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class Py3status:
# available configuration parameters
color = None
format = "{__v:.0f}"
join = None
join = ""
query = None
query_interval = 60
server = None
Expand All @@ -63,7 +63,7 @@ def prometheus(self):
self._rows = []
self._rownum = 0
rows = self._query(self.query)
res = []
res = self.py3.composite_create({})

for row in rows:
val = float(row["value"][1])
Expand All @@ -76,15 +76,10 @@ def prometheus(self):

vars = dict(row["metric"])
vars.update({"__v": val, "__n": num, "__u": unit})
res.append(self.format.format(**vars))

if res:
join = self.join or ""
res = join.join(res)
else:
res = ""
res = self.py3.composite_join("", self.py3.safe_format(self.format, vars))

ret = dict(full_text=res, cached_until=self.py3.time_in(self.query_interval))

if self.color:
if self.color.startswith("#"):
ret["color"] = self.color
Expand Down

0 comments on commit 8a9fc40

Please sign in to comment.