Pārlūkot izejas kodu

added uptime to email

tsi 5 gadi atpakaļ
vecāks
revīzija
866d8f92fc
1 mainītis faili ar 8 papildinājumiem un 1 dzēšanām
  1. 8 1
      scripts/send_email.py

+ 8 - 1
scripts/send_email.py

@@ -6,6 +6,13 @@ tmpdir = tempfile.TemporaryDirectory()
 beginning = str((1000*int(time.time()))-(17*3600000))
 beginning = str((1000*int(time.time()))-(17*3600000))
 end = str(1000*int(time.time()))
 end = str(1000*int(time.time()))
 
 
+
+def get_uptime():
+    with open('/proc/uptime', 'r') as f:
+        uptime_hours = round(float(f.readline().split()[0])/3600, 2)
+    return uptime_hours
+
+
 client = InfluxDBClient(host='127.0.0.1', port=8086, database='solar')
 client = InfluxDBClient(host='127.0.0.1', port=8086, database='solar')
 result = client.query("SELECT sum(\"eingespeiste_leistung\") *0.000002777777777 FROM \"Tannenstrasse\"  WHERE time >= " + beginning + "ms and time <= " + end + "ms")
 result = client.query("SELECT sum(\"eingespeiste_leistung\") *0.000002777777777 FROM \"Tannenstrasse\"  WHERE time >= " + beginning + "ms and time <= " + end + "ms")
 kwh = round(result.raw['series'][0]['values'][0][1], 1)
 kwh = round(result.raw['series'][0]['values'][0][1], 1)
@@ -39,7 +46,7 @@ msgText = MIMEText('This is the alternative plain text message.')
 msgAlternative.attach(msgText)
 msgAlternative.attach(msgText)
 
 
 # We reference the image in the IMG SRC attribute by the ID we give it below
 # We reference the image in the IMG SRC attribute by the ID we give it below
-msgText = MIMEText('<img src="cid:image1">', 'html')
+msgText = MIMEText('<img src="cid:image1"><br><p>Up: ' + str(get_uptime()) + ' Stunden</p>', 'html')
 msgAlternative.attach(msgText)
 msgAlternative.attach(msgText)
 
 
 # This example assumes the image is in the current directory
 # This example assumes the image is in the current directory