forked from doronz88/pymobiledevice3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimulate_location.py
executable file
·45 lines (37 loc) · 1.75 KB
/
simulate_location.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import struct
import time
import gpxpy
from pymobiledevice3.lockdown import LockdownClient
from pymobiledevice3.services.base_service import BaseService
class DtSimulateLocation(BaseService):
SERVICE_NAME = 'com.apple.dt.simulatelocation'
def __init__(self, lockdown: LockdownClient):
super().__init__(lockdown, self.SERVICE_NAME)
def clear(self):
""" stop simulation """
service = self.lockdown.start_developer_service(self.SERVICE_NAME)
service.sendall(struct.pack('>I', 1))
def set(self, latitude: float, longitude: float):
""" stop simulation """
service = self.lockdown.start_developer_service(self.SERVICE_NAME)
service.sendall(struct.pack('>I', 0))
latitude = str(latitude).encode()
longitude = str(longitude).encode()
service.sendall(struct.pack('>I', len(latitude)) + latitude)
service.sendall(struct.pack('>I', len(longitude)) + longitude)
def play_gpx_file(self, filename: str, disable_sleep: bool = False):
with open(filename) as f:
gpx = gpxpy.parse(f)
last_time = None
for track in gpx.tracks:
for segment in track.segments:
for point in segment.points:
if last_time is not None:
duration = (point.time - last_time).total_seconds()
if duration >= 0:
if not disable_sleep:
self.logger.info(f'waiting for {duration}s')
time.sleep(duration)
last_time = point.time
self.logger.info(f'set location to {point.latitude} {point.longitude}')
self.set(point.latitude, point.longitude)