-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathapple_baidumap.py
228 lines (205 loc) · 9.47 KB
/
apple_baidumap.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
#coding=utf-8
'''
The script is based on baidu map version 10.11.0,
which is theoretically compatible with less than 10.11.0
'''
__author__ = "Xu Tao"
__date__ = "2019-1-24"
__maintainer__ = 'Xu Tao'
from PA_runtime import *
import clr
try:
clr.AddReference('model_map_v2')
clr.AddReference("MapUtil")
clr.AddReference("bcp_gis")
except:
pass
del clr
import model_map_v2 as model_map
from collections import defaultdict
import traceback
import MapUtil
import bcp_gis
import json
import PA_runtime
class baiduMapParser(object):
def __init__(self, node, extract_deleted, extract_source):
self.root = node
self.extract_deleted = extract_deleted
self.extract_source = extract_source
self.cache = ds.OpenCachePath("baiduMap")
self.baidumap = model_map.Map()
def parse(self):
db_path = MapUtil.md5(self.cache, self.root.AbsolutePath) # 唯一路径
self.baidumap.db_create(db_path)
self.get_search_history()
self.get_navigation_record()
self.get_fav_position()
self.baidumap.db_close()
tmp_dir = ds.OpenCachePath("tmp")
PA_runtime.save_cache_path(bcp_gis.NETWORK_APP_MAP_BAIDU, db_path, tmp_dir)
result = model_map.ExportModel(db_path).get_model()
return result
def get_search_history(self):
"""
search history
"""
historyNode = self.root.Parent.Parent.Parent.GetByPath("Documents/his_record.sdb")
if historyNode is None:
return
db = SQLiteParser.Database.FromNode(historyNode, canceller)
if 'his_record' not in db.Tables:
return
tb = SQLiteParser.TableSignature('his_record')
for rec in db.ReadTableRecords(tb, True):
try:
if canceller.IsCancellationRequested:
return
search = model_map.Search()
if rec.Deleted == DeletedState.Deleted:
search.deleted = 1
search.sourceApp = "百度地图"
search.sourceFile = historyNode.AbsolutePath
if "key" in rec:
search.keyword = rec["key"].Value
if search.keyword:
self.baidumap.db_insert_table_search(search)
except Exception as e:
TraceService.Trace(TraceLevel.Error,"Get model_map.Search() Failed! -{0}".format(e))
self.baidumap.db_commit()
def get_navigation_record(self):
"""
navgation history
"""
hsAddressNode = self.root.Parent.Parent.Parent.GetByPath("Documents/routeHis_record.sdb")
if hsAddressNode is None:
return
try:
db = SQLiteParser.Database.FromNode(hsAddressNode, canceller)
if 'routeHis_record' not in db.Tables:
return
tb = SQLiteParser.TableSignature('routeHis_record')
for rec in db.ReadTableRecords(tb, True):
if canceller.IsCancellationRequested:
return
routeaddr = model_map.RouteRec()
if rec.Deleted == DeletedState.Deleted:
routeaddr.deleted = 1
routeaddr.sourceApp = "百度地图"
routeaddr.sourceFile = hsAddressNode.AbsolutePath
seach_history = rec["key"].Value
if "value" in rec and (not rec["value"].IsDBNull):
seach_info = rec["value"].Value
try:
b = bytes(seach_info)
jsonflie = b.decode('utf-16')
dicts = json.loads(jsonflie)
routeaddr.create_time = dicts.get("addtimesec")
routeaddr.from_name = dicts.get("sfavnode").get("name")
routeaddr.from_posX = dicts.get("sfavnode").get("geoptx")
routeaddr.from_posY = dicts.get("sfavnode").get("geopty")
routeaddr.to_name = dicts.get("efavnode").get("name")
routeaddr.to_posX = dicts.get("efavnode").get("geoptx")
routeaddr.to_posY = dicts.get("efavnode").get("geopty")
routeaddr.type = 6
except Exception as e:
continue
TraceService.Trace(TraceLevel.Error,"Get model_map.RouteRec() Failed! -{0}".format(e))
if routeaddr.from_name:
self.baidumap.db_insert_table_routerec(routeaddr)
except Exception as e:
TraceService.Trace(TraceLevel.Error,"Get model_map.RouteRec() Failed! -{0}".format(e))
self.baidumap.db_commit()
def get_fav_position(self):
"""
favorite history
"""
hsAddressNode = self.root.Parent.Parent.Parent.GetByPath("Documents/userCoreData/favCoreDataDB.sqlite")
if hsAddressNode is None:
return
try:
db = SQLiteParser.Database.FromNode(hsAddressNode, canceller)
if 'ZBMFAVPOI' not in db.Tables:
return
tb = SQLiteParser.TableSignature('ZBMFAVPOI')
for rec in db.ReadTableRecords(tb, True):
try:
if canceller.IsCancellationRequested:
return
favpoi = model_map.FavPoi()
loc = model_map.Location()
favpoi.fav_obj = loc.location_id
if rec.Deleted == DeletedState.Deleted:
favpoi.deleted = 1
favpoi.sourceApp = "百度地图"
favpoi.sourceFile = hsAddressNode.AbsolutePath
loc.sourceApp = "百度地图"
loc.sourceFile = hsAddressNode.AbsolutePath
loc.type = 6
if "ZNAME" in rec and (not rec["ZNAME"].IsDBNull):
favpoi.poi_name = rec["ZNAME"].Value
if "ZCITYID" in rec and (not rec["ZCITYID"].IsDBNull):
favpoi.city_id = rec["ZCITYID"].Value
if "ZCITYNAME" in rec and (not rec["ZCITYNAME"].IsDBNull):
favpoi.city_name = rec["ZCITYNAME"].Value
if "ZADDRESS" in rec and (not rec["ZADDRESS"].IsDBNull):
loc.address = rec["ZADDRESS"].Value
if "ZX" in rec and (not rec["ZX"].IsDBNull):
loc.longitude = rec["ZX"].Value
if "ZY" in rec and (not rec["ZY"].IsDBNull):
loc.latitude = rec["ZY"].Value
if loc.latitude and loc.longitude:
self.baidumap.db_insert_table_location(loc)
if favpoi.poi_name:
self.baidumap.db_insert_table_favpoi(favpoi)
except Exception as e:
TraceService.Trace(TraceLevel.Error,"Get model_map.FavPoi() Failed! -{0}".format(e))
except Exception as e:
TraceService.Trace(TraceLevel.Error,"Get model_map.FavPoi() Failed! -{0}".format(e))
dicts = defaultdict(list)
try:
db = SQLiteParser.Database.FromNode(hsAddressNode, canceller)
if 'ZBMFAVROUTENODE' not in db.Tables:
return
tb = SQLiteParser.TableSignature('ZBMFAVROUTENODE')
for rec in db.ReadTableRecords(tb, True):
try:
if canceller.IsCancellationRequested:
return
if "ZUSNAMESTRING" in rec and (not rec["ZUSNAMESTRING"].IsDBNull):
dicts[rec["ZFAVROUTERS"].Value].append(rec["ZUSNAMESTRING"].Value)
if "ZX" in rec and (not rec["ZX"].IsDBNull):
dicts[rec["ZFAVROUTERS"].Value].append(rec["ZX"].Value)
if "ZY" in rec and (not rec["ZY"].IsDBNull):
dicts[rec["ZFAVROUTERS"].Value].append(rec["ZY"].Value)
except Exception as e:
TraceService.Trace(TraceLevel.Error,"Get model_map.FavPoi() Failed! -{0}".format(e))
for key,value in dicts.items():
route_favpoi = model_map.FavPoi()
route_favpoi.sourceApp = "百度地图"
route_favpoi.sourceFile = hsAddressNode.AbsolutePath
route = model_map.FavRoute()
route.sourceApp = "百度地图"
route.sourceFile = hsAddressNode.AbsolutePath
route_favpoi.fav_obj = route.nav_id
route.from_name = value[0]
route.from_posX = value[1]
route.from_posY = value[2]
route.to_name = value[3]
route.to_posX = value[4]
route.to_posY = value[5]
route.type = 6
self.baidumap.db_insert_table_favroute(route)
self.baidumap.db_insert_table_favpoi(route_favpoi)
except Exception as e:
TraceService.Trace(TraceLevel.Error,"Get model_map.FavPoi() Failed! -{0}".format(e))
self.baidumap.db_commit()
def analyze_baidumap(root, extract_deleted, extract_source):
TraceService.Trace(TraceLevel.Info,"正在分析苹果百度地图...")
pr = ParserResults()
prResult = baiduMapParser(root, extract_deleted, extract_source).parse()
if prResult:
pr.Models.AddRange(prResult)
pr.Build("百度地图")
TraceService.Trace(TraceLevel.Info,"苹果百度地图分析完成!")
return pr