Added XML requests for plex, but will be replaced with a api request handling JSON objects instead. Also created cpuTemp for reading linux cpu temps, and added this to app API

This commit is contained in:
2017-02-08 13:35:09 +01:00
parent fb61212454
commit aea7491964
49 changed files with 30124 additions and 68 deletions

View File

@@ -1,15 +1,35 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# @Author: KevinMidboe
# @Date: 2017-01-28 13:56:48
# @Last Modified by: KevinMidboe
# @Last Modified time: 2017-01-28 13:58:35
import psutil
from pyspectator.processor import Cpu
from time import sleep
def getCpuTemp():
# Check if sensors_temperatures exists
try:
# Define cpu as function of sensors_temperatures
cpu = psutil.sensors_temperatures()
except AttributeError:
error = "'sensors_temperatures' is not supported in this verison of psutil or your OS."
print(error)
return None
cpu = Cpu(monitoring_latency=1)
with cpu:
for _ in range(8):
cpu.load, cpu.temperature
sleep(1.1)
# Array for temps for each core.
curCpuTemps = []
# Itterate through all cores of coretemps
for temp in cpu['coretemp']:
curCpuTemps.append(temp[1]) # Append to list
print(temp[0]+': '+str(temp[1])) # Print output
# Check if len of curCpuTemps is something so not to
# calculate on a empty list
if len(curCpuTemps) > 0:
# Compute avg of curCpuTemps
avgCpuTemps = sum(curCpuTemps)/len(curCpuTemps)
return avgCpuTemps
print("Avg: " + str(avgCpuTemps))
else:
print("Couldn't get cpu temp. (division by zero)")
return None
if __name__ == "__main__":
print(getCpuTemp())