Created
July 27, 2021 01:02
-
-
Save Garulf/295d6be11df7b023fc25e5198324b3ac to your computer and use it in GitHub Desktop.
iCUE log parser
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sys import argv, exit | |
from os import listdir, remove | |
from os.path import getctime, join | |
import json | |
log_dir = argv[1] | |
dir_list = listdir(log_dir) | |
logs = [] | |
for file in dir_list: | |
# Making sure we match log files so we dont delete important files | |
if file[:12] == 'corsair_cue_' and file[-4:] == '.csv': | |
logs.append(join(log_dir, file)) | |
if logs == []: | |
print('Error: Unable to find log files at:', log_dir) | |
exit(1) | |
most_recent_log = max(logs, key=getctime) | |
logs.remove(most_recent_log) | |
try: | |
if logs != []: | |
for file in logs: | |
file_path = join(log_dir, file) | |
# print('Removing old log:', file_path) | |
remove(file_path) | |
except PermissionError: | |
pass | |
# print('Error: Failed to purge older logs!') | |
# print(most_recent_log) | |
with open(join(log_dir, most_recent_log)) as f: | |
last_line = f.readlines()[-1].replace('\n', '').replace('°C', '').replace('RPM', '').replace('Â', '') | |
last_line = last_line.split(',') | |
for idx, _ in enumerate(last_line[:]): | |
if idx != 0: | |
last_line[idx] = float(last_line[idx]) | |
output = [ | |
{ | |
'sensors': last_line[1], | |
'name': 'Ambient Bottom Temperature' | |
}, | |
{ | |
'sensors': last_line[2], | |
'name': 'Side Chamber Temperature' | |
}, | |
{ | |
'sensors': last_line[3], | |
'name': 'Coolant Temperature' | |
}, | |
{ | |
'sensors': last_line[4], | |
'name': 'Ambient Back Temperature' | |
}, | |
{ | |
'fans': last_line[5], | |
'name': 'Bottom Rear Fan' | |
}, | |
{ | |
'fans': last_line[6], | |
'name': 'Rear Top Radiator Fan' | |
}, | |
{ | |
'pumps': last_line[7], | |
'name': 'Pump' | |
}, | |
{ | |
'fans': last_line[8], | |
'name': 'Front Top Radiator Fan' | |
}, | |
{ | |
'fans': last_line[9], | |
'name': 'Front Bottom Fan' | |
}, | |
{ | |
'fans': last_line[10], | |
'name': 'Front Case Fans' | |
} | |
] | |
for _ in output: | |
_['field'] = 'iCUE' | |
print(json.dumps(output)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment