tsi hace 5 años
padre
commit
9a19be4be0
Se han modificado 1 ficheros con 15 adiciones y 6 borrados
  1. 15 6
      scripts/send_email.py

+ 15 - 6
scripts/send_email.py

@@ -1,7 +1,16 @@
 import urllib.request, tempfile, smtplib, email, time
 from datetime import datetime
+from influxdb import InfluxDBClient
+
 tmpdir = tempfile.TemporaryDirectory() 
-urllib.request.urlretrieve("http://localhost:3000/render/d-solo/-wCxs6mgk/solaranlage?orgId=1&refresh=10s&panelId=2&from=" + str((1000*int(time.time()))-(24*3600000)) + "&to=" + str(1000*int(time.time())) + "&width=600&height=300&tz=Europe%2FBerlin", tmpdir.name + "/leistung.png")
+beginning = str((1000*int(time.time()))-(17*3600000))
+end = str(1000*int(time.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)
+
+urllib.request.urlretrieve("http://localhost:3000/render/d-solo/-wCxs6mgk/solaranlage?orgId=1&refresh=10s&panelId=2&from=" + beginning + "&to=" + end + "&width=600&height=300&tz=Europe%2FBerlin", tmpdir.name + "/leistung.png")
 
 # Send an HTML email with an embedded image and a plain text message for
 # email clients that don't want to display the HTML.
@@ -11,12 +20,12 @@ from email.mime.text import MIMEText
 from email.mime.image import MIMEImage
 
 # Define these once; use them twice!
-strFrom = 'net_flix_11@outlook.de'
-strTo = ["tobias.siegel@outlook.com", "t.siegel91@gmail.com","wsiegel@web.de"]
+strFrom = 'pv-tannenstr@web.de'
+strTo = ["tobias.siegel@outlook.com", "wsiegel@web.de"]
 
 # Create the root message and fill in the from, to, and subject headers
 msgRoot = MIMEMultipart('related')
-msgRoot['Subject'] = datetime.today().strftime('%Y-%m-%d') + ' Solaranlage'
+msgRoot['Subject'] = datetime.today().strftime('%Y-%m-%d') + ' - ' + str(kwh) + 'kWh - Solaranlage'
 msgRoot['From'] = strFrom
 msgRoot['To'] = ",".join(strTo)
 msgRoot.preamble = 'This is a multi-part message in MIME format.'
@@ -45,11 +54,11 @@ msgRoot.attach(msgImage)
 # Send the email (this example assumes SMTP authentication is required)
 import smtplib, ssl
 context = ssl.create_default_context()
-with smtplib.SMTP('smtp.outlook.com', 587) as server:
+with smtplib.SMTP('smtp.web.de', 587) as server:
     server.ehlo()  # Can be omitted
     server.starttls(context=context)
     server.ehlo()  # Can be omitted
-    server.login(strFrom, 'kathrein47')
+    server.login(strFrom, 'PV-Tannenstr')
     server.sendmail(strFrom, strTo, msgRoot.as_string())
 
 tmpdir.cleanup()