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
|
# Endlosschleife für die Abfrage alle 10 Minuten
|
||||||
devices = icloud.devices
|
try:
|
||||||
|
while True:
|
||||||
for device in devices:
|
# Standortdaten von Geräten abrufen
|
||||||
|
devices = icloud.devices
|
||||||
|
for device in devices:
|
||||||
location = device.location()
|
location = device.location()
|
||||||
if location:
|
if location:
|
||||||
device_name = device['name']
|
device_name = device['name']
|
||||||
|
@ -91,7 +93,16 @@ for device in devices:
|
||||||
VALUES (%s, %s, %s, %s)
|
VALUES (%s, %s, %s, %s)
|
||||||
""", (device_name, latitude, longitude, timestamp))
|
""", (device_name, latitude, longitude, timestamp))
|
||||||
|
|
||||||
# Änderungen speichern und Verbindung schließen
|
# Änderungen speichern
|
||||||
db.commit()
|
db.commit()
|
||||||
cursor.close()
|
|
||||||
db.close()
|
# 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