Skip to content

Commit ca92fd4

Browse files
committed
lm_sensors: update broken json parser
1 parent 9d20186 commit ca92fd4

1 file changed

Lines changed: 10 additions & 10 deletions

File tree

py3status/modules/lm_sensors.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,10 @@
160160
]
161161
"""
162162

163+
import re
163164
from collections import OrderedDict
164165
from fnmatch import fnmatch
165-
from json import JSONDecodeError, loads
166+
from json import loads
166167

167168
STRING_NOT_INSTALLED = "not installed"
168169

@@ -191,6 +192,7 @@ def post_config_hook(self):
191192
self.sensor_placeholders = [x for x in placeholders if x != "name"]
192193
self.format_sensor = self.py3.update_placeholder_formats(self.format_sensor, format_sensor)
193194

195+
self.pattern = re.compile(r'^}\n{$', re.MULTILINE)
194196
self.first_run = True
195197

196198
if self.chips:
@@ -228,15 +230,13 @@ def post_config_hook(self):
228230
def _get_lm_sensors_data(self):
229231
output = self.py3.command_output(self.lm_sensors_command)
230232
temporary = OrderedDict()
231-
chunk = ""
232-
233-
for line in output.splitlines():
234-
chunk += line
235-
try:
236-
temporary.update(loads(chunk))
237-
chunk = ""
238-
except JSONDecodeError:
239-
continue
233+
234+
for chunk in self.pattern.split(output.strip()):
235+
if not chunk.startswith("{"):
236+
chunk = "{" + chunk
237+
if not chunk.endswith("}"):
238+
chunk = chunk + "}"
239+
temporary.update(loads(chunk))
240240

241241
return temporary
242242

0 commit comments

Comments
 (0)