直线轨迹脚本
1 import json 2 import time 3 import random 4 import requests 5 from geopy import Point 6 from geopy.distance import Geodesic 7 from datetime import datetime, timedelta 8 9 10 def get_distance(point1, point2): 11 """根据经纬度获得两点之间的距离""" 12 return Geodesic.WGS84.Inverse(point1[0], point1[1], point2[0], point2[1])['s12'] 13 14 15 def simulate_path(starting_point, finishing_point, move_distance): 16 """模拟一段路径""" 17 total_distance = get_distance(starting_point, finishing_point) 18 distance_covered = 0 19 20 current_point = Point(starting_point) 21 path = [current_point] 22 23 while distance_covered < total_distance: 24 inv = Geodesic.WGS84.Inverse(current_point[0], current_point[1], finishing_point[0], finishing_point[1]) 25 bearing = inv['azi1'] 26 new_point = Geodesic.WGS84.Direct(current_point[0], current_point[1], bearing, move_distance) 27 current_point = Point(new_point['lat2'], new_point['lon2']) 28 path.append(current_point) 29 distance_covered += move_distance 30 31 path.append(Point(finishing_point)) 32 return path 33 34 35 if __name__ == '__main__': 36 start_point = (31.38544, 121.71109) 37 end_point = (31.276376, 121.412926) 38 step = 100 # 每个点之间的距离(米) 39 40 path = simulate_path(start_point, end_point, step) 41 now = datetime.now() # 获取当前时间 42 43 allowed_location_type = [0, 1, 2, 3, 4, 5, 6, 8, 9, 11] 44 url = "https://qa-b.51kuafu.com/tiger/kms/api/attendance/dailyPointTraceUpload" 45 token='eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJhdWQiOiIzIiwianRpIjoiNzk1OTFhYWExZjI2MTVjOWY1YjBlMDkwZmZkZGU3Y2Y0YWIyMDdhMDgyNmQzNDNjMjViNTAzMzJkMjFiZTZhNWNjNDMxM2NiZWE0Y2NkODYiLCJpYXQiOjE2ODM3MDY1MzgsIm5iZiI6MTY4MzcwNjUzOCwiZXhwIjoxNjg2Mjk4NTM4LCJzdWIiOiIyODMwIiwic2NvcGVzIjpbIioiXSwiaXAiOiI1OC4zNC4xNjMuMTY2IiwidXNlcl9pZCI6IjI4MzAiLCJ0eXBlIjoia21zIn0.KvjU9LdshcB2t-LBg032uDJ3yeH4yJB1IWsfW5CzOfz1SMhPmaP5No-wlZJ4wsVCZ1lP4OCC_0pdhqvgByKi8PU15-6q7ixgtHrziw9xDSh3MNcNvJGw6cgBl06M-WOTmwc8x6JvrPP8Bda9jthC8gjWcBhI2s0D5OlCwqty4QGDkl9Hkxfv0679jkfvuNOV0wEeYvgjhPZgLwN20nyPyrIB7z6Ks0_dI0JzdWq80lKwMBkT0DseCfCmOLbdNQhqLALKOd8jKLj0HH6mYv0VK1ch2dljvKR_JpOihTImASvLK-cVq_BZ5dVg6hJSpvTadO6Y7gjd58elQIt8CQW_jcPEVAaKBwl2YmqAJL9uPCKD1ZSx4BgbJG6Ltpf7NCyXMM9UTM1yWeb6iLgSCzoUVGDW-PpAW2VI0Fsxi0MEUxVMJTaOBBK8qEyD3IX1c0ioAuVB5fQ0B34gM5YUVZ8f3HYaPQ4Vlgw6KLokSGwLaurK3s5k_a7JQdjSUqg6-GgW-pxHvURkLOFARbEa48s5vySxec6bUtBy5jeIwD_kmm4ye_E7bNzngtAOyhg16luhxz5-t-kGYVMEcB--Kbo4cT-bNTCXIoaRzKGtVmel8jLsu8YYhLgwzP_sk338-1SYdi8WdvXxFJoddMIZ7QSDWh6QoZlr5l7ByUsdjIA9nFU' 46 headers = { 47 'version': '1.2.1', 48 'Content-Type': 'application/json', 49 'Authorization': 'Bearer ' + token 50 } 51 payload = { 52 "tracePoints": [] 53 } 54 55 # 打印路径上的经纬度 56 for point in path: 57 tracePoints_data = { 58 "gpsSwitch": 1, 59 "wifiSwitch": 1, 60 "cellularNetworkSwitch": 0, 61 "dumpEnergy": 13, 62 "longitude": str(round(point.longitude, 6)), 63 "latitude": str(round(point.latitude, 6)), 64 "tracePointTime": now.strftime('%Y-%m-%d %H:%M:%S'), 65 "deviceModel": "RMX3372", 66 "deviceSystem": "Android 13", 67 "deviceSerialNumber": "6094f9b4b180deb76cc2bf9498613ab1644e94ef", 68 "extra": { 69 "time": 1683683139015, 70 "speed": 0, 71 "offset": True, 72 "heading": 0, 73 "version": "1.4.1", 74 "accuracy": random.uniform(1, 100), 75 "altitude": 0, 76 "latitude": round(point.latitude, 6), 77 "provider": "lbs", 78 "coordType": "GCJ02", 79 "errorCode": 0, 80 "errorInfo": "success", 81 "is_mocked": False, 82 "longitude": round(point.longitude, 6), 83 "locationType": random.choice(allowed_location_type), 84 "locationDetail": "#id:SbWpoaWxwc29oZmRkY2k3Nzg4ZTloZGQ2MmVlZjNkLA==#csid:a42807ea334b4735bc03eb1f911b8ea2#pm111111", 85 "speed_accuracy": 0, 86 "isFixLastLocation": False 87 } 88 } 89 payload['tracePoints'].append(tracePoints_data) 90 now += timedelta(seconds=random.randint(1, 60)) # 随机增加30秒 91 # print(payload) 92 response = requests.request("POST", url, headers=headers, data=json.dumps(payload)) 93 print(response.json())
高德模拟行进轨迹脚本
1 import json 2 import time 3 import random 4 import requests 5 from geopy import Point 6 from geopy.distance import Geodesic 7 from datetime import datetime, timedelta 8 9 10 def find_route(api_key, origin, destination, mode="driving"): 11 """获取路径规划""" 12 url = "https://restapi.amap.com/v3/direction/{mode}".format(mode=mode) 13 params = { 14 "key": api_key, 15 "origin": origin, 16 "destination": destination, 17 "output": "json" 18 } 19 20 response = requests.get(url, params=params) 21 data = response.json() 22 # print(data) 23 return data 24 25 26 def extract_route_coordinates(route_data): 27 coordinates = [] 28 29 if "route" in route_data and "paths" in route_data["route"]: 30 for path in route_data["route"]["paths"]: 31 if "steps" in path: 32 for step in path["steps"]: 33 if "polyline" in step: 34 polyline = step["polyline"] 35 coords = polyline.split(";") 36 for coord in coords: 37 lng, lat = coord.split(",") 38 coordinates.append((float(lng), float(lat))) 39 return coordinates 40 41 42 if __name__ == "__main__": 43 api_key = "01b1f9293f48232c84d845207ade02ce" 44 origin = "121.81499,31.15708" # 经纬度格式 lon,lat(经度,纬度) 45 destination = "121.25340,31.01064" 46 mode = "driving" # 可选值:driving(驾车)、walking(步行)、bicycling(骑行)、transit(公交) 47 route_data = find_route(api_key, origin, destination, mode) 48 route_coordinates = extract_route_coordinates(route_data) 49 # print(route_coordinates) 50 51 now = datetime.now() # 获取当前时间 52 allowed_location_type = [1, 2, 4, 5, 6, 8, 9, 11] 53 54 url = "https://qa-b.51kuafu.com/tiger/kms/api/attendance/dailyPointTraceUpload" 55 token='eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJhdWQiOiIzIiwianRpIjoiYmJjOWFlMjhlYmE5MGFkMWRmOTcwMDM1YWYwNjlkMjczNjA4OGJiMDU1MzgzNWY1NTY1YjM5NzI4ZmUyOTk4OTEyYmYzNzJhNTUwOTAxNjMiLCJpYXQiOjE2ODM4NzMzNDMsIm5iZiI6MTY4Mzg3MzM0MywiZXhwIjoxNjg2NDY1MzQzLCJzdWIiOiI2NyIsInNjb3BlcyI6WyIqIl0sImlwIjoiNTguMzQuMTYzLjE2NiIsInVzZXJfaWQiOiI2NyIsInR5cGUiOiJrbXMifQ.QkFKC0R1qKvFemfxflvsfu6GSZF6uho8lqUFsg7DVNhqCoSLg3a9FkreNDuCCMh6u9PzCxZ9nsQjCno_alM7wf1KVBvmfxJOGW-ag4-fB32rbd7IadECyKhzpnUepafYPU80ScQt9UwgluexSAjgbGjXZv__iIrb59YtiGyv_gStunvy5shFdDU--rkG41rA2Fp3yMVeB6JM-2-f_N387TfNf-ZcLMePxrdjjU1gF5PRHLnZJOOKqzXOmyiNxy9S4zNlBgx6wOiFn9tIMv6grtQae-YW3-skHi0fX4NZuJpPOX7OyYo--5-Ks3p0LJqz1sXV6V-wwgcXnRx1Xo8Um0TltQwcxJKYK3IpZbUWgeMRG6owX79ydVdHJNBaYzWzRS_bq7FQ1UWo2Ppw-Gi_gbIuAgS3kvLuFurA0yggWPSDfCCyFvgTPqBPve8ukWBGozXMawSz-FnBS0DuGep99mH8etazOh5JUFVAesRb69-wUCnLM7Axce5sZbzv7sx_js_ugHv0jBzgITOHuWqFkOxKCVJfPf5e1AR6WHZEFPjlDHOMTT2Iy7GWepgFGXahyWU7o0gOLH2zPSO5BR0hUCGeosuUf4q4moRmadaMOjpk_hAGnMCSJu3sTWb9ADianJ6YJX76fbvHNu3VZz3sxXqWewp7wevRfjoxjPcwD_E' 56 headers = { 57 'version': '1.2.1', 58 'Content-Type': 'application/json', 59 'Authorization': 'Bearer ' + token 60 } 61 payload = { 62 "tracePoints": [] 63 } 64 65 # 打印路径上的经纬度 66 for point in route_coordinates: 67 # print(point) 68 tracePoints_data = { 69 "gpsSwitch": 1, 70 "wifiSwitch": 1, 71 "cellularNetworkSwitch": 0, 72 "dumpEnergy": 13, 73 "longitude": str(round(point[0], 6)), 74 "latitude": str(round(point[1], 6)), 75 "tracePointTime": now.strftime('%Y-%m-%d %H:%M:%S'), 76 "deviceModel": "RMX3372", 77 "deviceSystem": "Android 13", 78 "deviceSerialNumber": "6094f9b4b180deb76cc2bf9498613ab1644e94ef", 79 "extra": { 80 "time": 1683683139015, 81 "speed": 0, 82 "offset": True, 83 "heading": 0, 84 "version": "1.4.1", 85 "accuracy": random.uniform(1, 50), 86 "altitude": 0, 87 "latitude": str(round(point[1], 6)), 88 "provider": "lbs", 89 "coordType": "GCJ02", 90 "errorCode": 0, 91 "errorInfo": "success", 92 "is_mocked": False, 93 "longitude": str(round(point[0], 6)), 94 "locationType": random.choice(allowed_location_type), 95 "locationDetail": "#id:SbWpoaWxwc29oZmRkY2k3Nzg4ZTloZGQ2MmVlZjNkLA==#csid:a42807ea334b4735bc03eb1f911b8ea2#pm111111", 96 "speed_accuracy": 0, 97 "isFixLastLocation": False 98 } 99 } 100 # print(tracePoints_data) 101 payload['tracePoints'].append(tracePoints_data) 102 now += timedelta(seconds=random.randint(30, 90)) # 随机增加30秒 103 print(payload) 104 response = requests.request("POST", url, headers=headers, data=json.dumps(payload)) 105 print(response.json())
标签:脚本,distance,轨迹,point,route,path,import,data From: https://www.cnblogs.com/CSgarcia/p/18647626