Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import time
- import MySQLdb as mysql
- import simplemail
- db = mysql.connect(host="localhost", user="root", passwd="234234", db="projekt")
- def senden(mail,min):
- simplemail.Email(
- smtp_server = "",
- smtp_user = "",
- smtp_password = "",
- from_address = "",
- to_address = mail,
- subject = u"Alarm!",
- message = u"Ein Alarm wurde nach "+min+""" Minuten um nicht deaktiviert.
- Bitte Deaktivieren Sie denn Alarm oder leiten sie gegebenfalls weitere Schritte ein."""
- ).send()
- print("Email Versendet")
- Alarm_Zeit = 0
- Alarm_set = 0
- min1 = 0
- min2 = 0
- while True:
- time.sleep(1)
- cursor = db.cursor()
- cursor.execute("""SELECT * From projekt""")
- db.commit()
- Alarm = cursor.fetchone()[1]
- zeit = time.time()
- if Alarm == 1 and Alarm_set == 0:
- Alarm_Zeit = zeit
- Alarm_set = 1
- print(Alarm_Zeit)
- akt = zeit-Alarm_Zeit
- print(akt)
- if akt > 5.0 and min1 == 0 and Alarm == 1:
- print("Alarm nach 5 nicht deaktivert")
- senden("office@jakobstadlhuber.com","5")
- min1 = 1
- if akt > 10.0 and min2 == 0 and Alarm == 1:
- min2 = 1
- print("Alarm nach 10 nicht deaktiviert")
- senden("privat@jakobstadlhuber.com","10")
- if Alarm == 0:
- Alarm_Zeit = 0
- Alarm_set = 0
- min1 = 0
- min2 = 0
- db.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement