set while loop every 10 minutes
This commit is contained in:
parent
3a10ed38cc
commit
6a9eedb7ba
1 changed files with 31 additions and 20 deletions
27
script.py
27
script.py
|
@ -71,10 +71,12 @@ cursor.execute("""
|
|||
)
|
||||
""")
|
||||
|
||||
# Standortdaten abrufen
|
||||
devices = icloud.devices
|
||||
|
||||
for device in devices:
|
||||
# Endlosschleife für die Abfrage alle 10 Minuten
|
||||
try:
|
||||
while True:
|
||||
# Standortdaten von Geräten abrufen
|
||||
devices = icloud.devices
|
||||
for device in devices:
|
||||
location = device.location()
|
||||
if location:
|
||||
device_name = device['name']
|
||||
|
@ -91,7 +93,16 @@ for device in devices:
|
|||
VALUES (%s, %s, %s, %s)
|
||||
""", (device_name, latitude, longitude, timestamp))
|
||||
|
||||
# Änderungen speichern und Verbindung schließen
|
||||
db.commit()
|
||||
cursor.close()
|
||||
db.close()
|
||||
# Änderungen speichern
|
||||
db.commit()
|
||||
|
||||
# 10 Minuten warten
|
||||
logging.info("Warten auf die nächste Abfrage in 10 Minuten...")
|
||||
time.sleep(600)
|
||||
|
||||
except KeyboardInterrupt:
|
||||
logging.info("Skript manuell beendet.")
|
||||
|
||||
finally:
|
||||
cursor.close()
|
||||
db.close()
|
||||
|
|
Loading…
Reference in a new issue