-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemperature.py
More file actions
29 lines (25 loc) · 845 Bytes
/
temperature.py
File metadata and controls
29 lines (25 loc) · 845 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import os, sys, subprocess
#from avg import avg
#getting the current system temperature
command = "sudo /usr/bin/vcgencmd measure_temp"
currentResult = os.popen(command).read()
currentResult = currentResult[5:9]
#reading the file
with open('temperature.txt', 'r') as f:
lineas = [linea.split("=") for linea in f]
f.close()
temperatureReaded = ' '
#reading the file's temperature
for linea in lineas:
temperatureReaded = linea[0]
#parsing
temperatureReaded = temperatureReaded[:4]
f = open('temperature.txt', 'w')
if currentResult > temperatureReaded:
f.write ("The temperature is increased, current temperature: \n" + currentResult + "\n")
else:
f.write ("The temperature is decreased, current temperature: \n" + currentResult + "\n")
f.close()
f = open('history_temperature.txt','a')
f.write(currentResult + '\n')
f.close()