tsi 5 anni fa
parent
commit
9b752cabcd
1 ha cambiato i file con 13 aggiunte e 4 eliminazioni
  1. 13 4
      scripts/send_email.py

+ 13 - 4
scripts/send_email.py

@@ -1,18 +1,23 @@
 import urllib.request, tempfile, smtplib, email, time
-from datetime import datetime
+from datetime import datetime, timedelta
 from influxdb import InfluxDBClient
 
 tmpdir = tempfile.TemporaryDirectory() 
 beginning = str((1000*int(time.time()))-(17*3600000))
 end = str(1000*int(time.time()))
 
+def get_boot_time():
+    with open('/proc/uptime', 'r') as f:
+        uptime_seconds = int(float(f.readline().split()[0]))
+        boot_time = datetime.now() - timedelta(seconds=uptime_seconds) + timedelta(hours=1)
+    return boot_time
 
 def get_uptime():
     with open('/proc/uptime', 'r') as f:
         uptime_hours = round(float(f.readline().split()[0])/3600, 2)
     return uptime_hours
 
-
+get_boot_time()
 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")
 kwh = round(result.raw['series'][0]['values'][0][1], 1)
@@ -45,8 +50,12 @@ msgRoot.attach(msgAlternative)
 msgText = MIMEText('This is the alternative plain text message.')
 msgAlternative.attach(msgText)
 
-# We reference the image in the IMG SRC attribute by the ID we give it below
-msgText = MIMEText('<img src="cid:image1"><br><p>Up: ' + str(get_uptime()) + ' Stunden</p>', 'html')
+# Get Boot Time and Convert it to String
+bt = get_boot_time()
+bt_str = bt.strftime("%d.%m.%Y, %H.%M")
+
+# We reference the image in the IMG SRC attribute by the ID we give it dasdasdbelow
+msgText = MIMEText('<img src="cid:image1"><br><p>Letzter Start: ' + bt_str + ' Uhr</p>', 'html')
 msgAlternative.attach(msgText)
 
 # This example assumes the image is in the current directory