Advertisement
Guest User

Untitled

a guest
Dec 7th, 2015
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.39 KB | None | 0 0
  1. #!/usr/bin/env python
  2. import time
  3. import MySQLdb as mysql
  4. import simplemail
  5. db = mysql.connect(host="localhost", user="root", passwd="234234", db="projekt")
  6.  
  7.  
  8. def senden(mail,min):
  9.     simplemail.Email(
  10.     smtp_server = "",
  11.     smtp_user = "",
  12.     smtp_password = "",
  13.     from_address = "",
  14.     to_address = mail,
  15.     subject = u"Alarm!",
  16.     message = u"Ein Alarm wurde nach "+min+""" Minuten um nicht deaktiviert.
  17.  
  18.                Bitte Deaktivieren Sie denn Alarm oder leiten sie gegebenfalls weitere Schritte ein."""
  19.     ).send()
  20.     print("Email Versendet")
  21.  
  22.  
  23. Alarm_Zeit = 0
  24. Alarm_set = 0
  25. min1 = 0
  26. min2 = 0
  27.  
  28. while True:
  29.     time.sleep(1)
  30.     cursor = db.cursor()
  31.     cursor.execute("""SELECT * From projekt""")
  32.     db.commit()
  33.     Alarm = cursor.fetchone()[1]
  34.     zeit = time.time()
  35.     if Alarm == 1 and Alarm_set == 0:
  36.         Alarm_Zeit = zeit
  37.         Alarm_set = 1
  38.         print(Alarm_Zeit)
  39.     akt = zeit-Alarm_Zeit
  40.     print(akt)
  41.     if akt > 5.0 and min1 == 0 and Alarm == 1:
  42.         print("Alarm nach 5 nicht deaktivert")
  43.         senden("office@jakobstadlhuber.com","5")
  44.         min1 = 1
  45.     if akt > 10.0 and min2 == 0 and Alarm == 1:
  46.         min2 = 1
  47.         print("Alarm nach 10 nicht deaktiviert")
  48.         senden("privat@jakobstadlhuber.com","10")
  49.     if Alarm == 0:
  50.         Alarm_Zeit = 0
  51.         Alarm_set = 0
  52.         min1 = 0
  53.         min2 = 0
  54.  
  55. db.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement