Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- #
- # by OuNiS 11.2023
- #
- # https://pastebin.com/gq9VmYZd
- '''
- .json file structure
- {
- "coretemp-isa-0000":{
- "Adapter": "ISA adapter",
- "Package id 0":{
- "temp1_input": 36.000,
- "temp1_max": 80.000,
- "temp1_crit": 100.000,
- "temp1_crit_alarm": 0.000
- },
- "Core 0":{
- "temp2_input": 36.000,
- "temp2_max": 80.000,
- "temp2_crit": 100.000,
- "temp2_crit_alarm": 0.000
- },
- "Core 1":{
- "temp3_input": 35.000,
- "temp3_max": 80.000,
- "temp3_crit": 100.000,
- "temp3_crit_alarm": 0.000
- }
- }
- }
- '''
- import json
- import os
- import pathlib
- import sys
- MAIN_FILE_NAME =sys.argv[0].split("/")[-1]
- SENSORS_JSON_FILE = ".".join([MAIN_FILE_NAME,"json~"])
- # print(SENSORS_JSON_FILE)
- # uruchomienie sensors, wynik w json zapisany do pliku
- os.system("sensors -A -j > {}".format(SENSORS_JSON_FILE))
- print("Czas pomiaru: ")
- # os.system("~/batch/script_header")
- os.system("date +\"%Y-%m-%d %H:%M:%S\"")
- lines = []
- with open(SENSORS_JSON_FILE) as file:
- lines = file.readlines()
- sensj = json.loads("".join(lines))
- print("Keys: ")
- #for k in sensj.keys():
- # print(k)
- for k in sensj.get("coretemp-isa-0000") .keys():
- print(k)
- CPU_TEMP = sensj.get("coretemp-isa-0000").get("Package id 0").get("temp1_input")
- CORE_0_TEMP = sensj.get("coretemp-isa-0000").get("Core 0").get("temp2_input")
- CORE_1_TEMP = sensj.get("coretemp-isa-0000").get("Core 1").get("temp3_input")
- print(f'CPU temp: {CPU_TEMP}')
- print(f'\tCore 0 temp: {CORE_0_TEMP}')
- print(f'\tCore 1 temp: {CORE_1_TEMP}')
- # Cleaning...
- pathlib.Path.unlink(SENSORS_JSON_FILE, missing_ok=True)
- # try:
- # # try to erase temp file...
- #
- # pathlib.Path.unlink(SENSORS_JSON_FILE)
- # except Exception as err:
- # # maybe file disappeard by yourself...
- # # well, do nothing...
- # ...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement