Advertisement
Guest User

Untitled

a guest
Jul 28th, 2016
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 22.03 KB | None | 0 0
  1. import requests
  2. import re
  3. import json
  4. import argparse
  5. import POGOProtos
  6. import POGOProtos.Data_pb2
  7. import POGOProtos.Enums_pb2
  8. import POGOProtos.Inventory_pb2
  9. import POGOProtos.Map_pb2
  10. import POGOProtos.Settings_pb2
  11. import POGOProtos.Networking
  12. import POGOProtos.Networking.Envelopes_pb2
  13. import POGOProtos.Networking.Requests_pb2
  14. import POGOProtos.Networking.Responses_pb2
  15. import POGOProtos.Networking.Requests
  16. import POGOProtos.Networking.Requests.Messages_pb2
  17.  
  18. import time
  19.  
  20. from datetime import datetime
  21. #from geopy.geocoders import GoogleV3
  22. from requests.packages.urllib3.exceptions import InsecureRequestWarning
  23. requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
  24. from s2sphere import *
  25.  
  26.  
  27. def getNeighbors():
  28. origin = CellId.from_lat_lng(LatLng.from_degrees(FLOAT_LAT, FLOAT_LNG)).parent(15)
  29.  
  30. level = 15
  31. max_size = 1 << 30
  32. size = origin.get_size_ij(level)
  33.  
  34. face, i, j = origin.to_face_ij_orientation()[0:3]
  35.  
  36. walk= [origin.id(),
  37. origin.from_face_ij_same(face, i, j - size, j - size >= 0).parent(level).id(),
  38. origin.from_face_ij_same(face, i, j + size, j + size < max_size).parent(level).id(),
  39. origin.from_face_ij_same(face, i - size, j, i - size >= 0).parent(level).id(),
  40. origin.from_face_ij_same(face, i + size, j, i + size < max_size).parent(level).id(),
  41. origin.from_face_ij_same(face, i - size, j - size, j - size >= 0 and i - size >=0).parent(level).id(),
  42. origin.from_face_ij_same(face, i + size, j - size, j - size >= 0 and i + size < max_size).parent(level).id(),
  43. origin.from_face_ij_same(face, i - size, j + size, j + size < max_size and i - size >=0).parent(level).id(),
  44. origin.from_face_ij_same(face, i + size, j + size, j + size < max_size and i + size < max_size).parent(level).id()]
  45. #origin.from_face_ij_same(face, i, j - 2*size, j - 2*size >= 0).parent(level).id(),
  46. #origin.from_face_ij_same(face, i - size, j - 2*size, j - 2*size >= 0 and i - size >=0).parent(level).id(),
  47. #origin.from_face_ij_same(face, i + size, j - 2*size, j - 2*size >= 0 and i + size < max_size).parent(level).id(),
  48. #origin.from_face_ij_same(face, i, j + 2*size, j + 2*size < max_size).parent(level).id(),
  49. #origin.from_face_ij_same(face, i - size, j + 2*size, j + 2*size < max_size and i - size >=0).parent(level).id(),
  50. #origin.from_face_ij_same(face, i + size, j + 2*size, j + 2*size < max_size and i + size < max_size).parent(level).id(),
  51. #origin.from_face_ij_same(face, i + 2*size, j, i + 2*size < max_size).parent(level).id(),
  52. #origin.from_face_ij_same(face, i + 2*size, j - size, j - size >= 0 and i + 2*size < max_size).parent(level).id(),
  53. #origin.from_face_ij_same(face, i + 2*size, j + size, j + size < max_size and i + 2*size < max_size).parent(level).id(),
  54. #origin.from_face_ij_same(face, i - 2*size, j, i - 2*size >= 0).parent(level).id(),
  55. #origin.from_face_ij_same(face, i - 2*size, j - size, j - size >= 0 and i - 2*size >=0).parent(level).id(),
  56. #origin.from_face_ij_same(face, i - 2*size, j + size, j + size < max_size and i - 2*size >=0).parent(level).id()]
  57.  
  58. return walk
  59.  
  60.  
  61.  
  62. API_URL = 'https://pgorelease.nianticlabs.com/plfe/rpc'
  63. LOGIN_URL = 'https://sso.pokemon.com/sso/login?service=https%3A%2F%2Fsso.pokemon.com%2Fsso%2Foauth2.0%2FcallbackAuthorize'
  64. LOGIN_OAUTH = 'https://sso.pokemon.com/sso/oauth2.0/accessToken'
  65.  
  66. SESSION = requests.session()
  67. SESSION.verify = False
  68. NET_MAXWAIT = 30
  69. LOGIN_MAXWAIT = 5
  70. MAXWAIT = LOGIN_MAXWAIT
  71.  
  72. FLOAT_LAT = 0
  73. FLOAT_LNG = 0
  74. FLOAT_ALT = 0
  75. EARTH_Rmax = 6378137.0
  76. EARTH_Rmin = 6356752.3
  77. HEX_R = 100.0 #range of detection for pokemon = 100m
  78. HEX_M = 3.0**(0.5)/2.0*HEX_R
  79. LAT_C,LNG_C,ALT_C = [39.952532, -74.197443, 5]
  80. safety=1.0
  81.  
  82. HEX_NUM = 0
  83. DATA = []
  84. LOGGING = False
  85. wID = 0
  86.  
  87. login_type=''
  88. api_endpoint = ''
  89. access_token = ''
  90. response = {}
  91. r = None
  92.  
  93. LANGUAGE='english' #'german' and 'english' supported
  94.  
  95. LI_TYPE='ptc' #'google'#
  96. users_ptc= ['tomsriverscan','verizonscan','seasidescan','homescan','grimescan']
  97. passwords_ptc = ['griffey0','griffey0','griffey0','griffey0','griffey0']
  98.  
  99. users_google=['agent0@gmail.com','agent1@gmail.com']
  100. passwords_google=['secretpassword','secretpassword']
  101.  
  102. li_user=''
  103. li_password=''
  104.  
  105. def prune_data():
  106. # prune despawned pokemon
  107. cur_time = int(time.time())
  108. for i, poke in reversed(list(enumerate(DATA))):
  109. if cur_time>poke['despawnTime']:
  110. DATA.pop(i)
  111.  
  112. def write_data_to_file(DATA_FILE):
  113. try:
  114. f = open(DATA_FILE, 'w')
  115. json.dump(DATA, f, indent=2)
  116. finally:
  117. f.close()
  118.  
  119. def add_pokemon(pokeId, spawnID, lat, lng, despawnT):
  120. DATA.append({
  121. 'id': pokeId,
  122. 'spawnID': spawnID,
  123. 'lat': lat,
  124. 'lng': lng,
  125. 'despawnTime': despawnT,
  126. });
  127.  
  128. def getEarthRadius(latrad):
  129. return (1.0/(((math.cos(latrad))/EARTH_Rmax)**(2) + ((math.sin(latrad))/EARTH_Rmin)**(2)))**(1.0/2)
  130.  
  131. def set_location_coords(lat, lng, alt):
  132. global FLOAT_LAT, FLOAT_LNG, FLOAT_ALT
  133. FLOAT_LAT = lat
  134. FLOAT_LNG = lng
  135. FLOAT_ALT = alt
  136.  
  137. def init_location():
  138. #latrad=LAT_C*math.pi/180
  139.  
  140. #a=(HEX_NUM+0.5)
  141. #x_un=1.5*HEX_R/getEarthRadius(latrad)/math.cos(latrad)*safety*a*180/math.pi
  142. #y_un=3.0*HEX_M/getEarthRadius(latrad)*safety*a*180/math.pi
  143. #xmod=[0,1,2,1,-1,-2,-1]
  144. #ymod=[0,-1,0,1,1,0,-1]
  145. #lat = LAT_C+ymod[wID]*y_un
  146. #lng = LNG_C+xmod[wID]*x_un
  147. if wID==0:
  148. lat,lng = (39.952532, -74.197443)
  149. elif wID==1:
  150. lat,lng = (40.200451, -74.645449)
  151. elif wID==2:
  152. lat,lng = (39.944182, -74.074567)
  153. elif wID==3:
  154. lat,lng = (39.963259, -74.266054)
  155. else:
  156. lat,lng = (40.051579, -74.196539)
  157. set_location_coords(lat,lng,ALT_C)
  158.  
  159. def login_google(username,password):
  160. global access_token
  161. global login_type
  162. login_type='google'
  163. return None
  164.  
  165. def login_ptc(username, password):
  166. global access_token
  167. global login_type
  168. login_type='ptc'
  169. r = None
  170. while True:
  171. try:
  172. #SESSION.headers.update({'User-Agent': 'Niantic App'})
  173. SESSION.headers.update({'User-Agent': 'niantic'})
  174. r = SESSION.get(LOGIN_URL)
  175. retry_after=1
  176. while r.status_code!=200:
  177. print('[-] Connection error {}, retrying in {} seconds (step 1)'.format(r.status_code,retry_after))
  178. time.sleep(retry_after)
  179. retry_after=min(retry_after*2,MAXWAIT)
  180. r = SESSION.get(LOGIN_URL)
  181.  
  182.  
  183. jdata = json.loads(r.content)
  184. data = {
  185. 'lt': jdata['lt'],
  186. 'execution': jdata['execution'],
  187. '_eventId': 'submit',
  188. 'username': username,
  189. 'password': password,
  190. }
  191. r = SESSION.post(LOGIN_URL, data=data)
  192. retry_after=1
  193.  
  194. while r.status_code!=500 and r.status_code!=200:
  195. print('[-] Connection error {}, retrying in {} seconds (step 2)'.format(r.status_code,retry_after))
  196. time.sleep(retry_after)
  197. retry_after=min(retry_after*2,MAXWAIT)
  198. r = SESSION.post(LOGIN_URL, data=data)
  199.  
  200. ticket = None
  201. ticket = re.sub('.*ticket=', '', r.history[0].headers['Location'])
  202. data1 = {
  203. 'client_id': 'mobile-app_pokemon-go',
  204. 'redirect_uri': 'https://www.nianticlabs.com/pokemongo/error',
  205. 'client_secret': 'w8ScCUXJQc6kXKw8FiOhd8Fixzht18Dq3PEVkUCP5ZPxtgyWsbTvWHFLm2wNY0JR',
  206. 'grant_type': 'refresh_token',
  207. 'code': ticket,
  208. }
  209. r = SESSION.post(LOGIN_OAUTH, data=data1)
  210. while r.status_code!=200:
  211. print('[-] Connection error {}, retrying in {} seconds (step 3)'.format(r.status_code,retry_after))
  212. time.sleep(retry_after)
  213. retry_after=min(retry_after*2,MAXWAIT)
  214. r = SESSION.post(LOGIN_OAUTH, data=data1)
  215.  
  216. access_token = re.sub('&expires.*', '', r.content)
  217. access_token = re.sub('.*access_token=', '', access_token)
  218. return
  219.  
  220. except Exception,e:
  221. print('[-] Uncaught connection error, error: {}'.format(e))
  222. if r is not None:
  223. print('[-] Uncaught connection error, http code: {}'.format(r.status_code))
  224. else:
  225. print('[-] Error happened before network request.')
  226. print('[-] Retrying...')
  227. time.sleep(2)
  228.  
  229. def do_login():
  230. if LI_TYPE=='ptc':
  231. li_user = users_ptc[wID]
  232. li_password = passwords_ptc[wID]
  233. print('[+] login for ptc account: {}'.format(li_user))
  234. login_ptc(li_user,li_password)
  235. elif LI_TYPE=='google':
  236. li_user = users_google[wID]
  237. li_password = passwords_google[wID]
  238. print('[+] login for google account: {}'.format(li_user))
  239. login_google(li_user,li_password)
  240. else:
  241. raise Exception('login type should be either ptc or google')
  242.  
  243. def api_req(api_endpoint, access_token, *mehs, **kw):
  244. r=None;
  245. while True:
  246. try:
  247. p_req = POGOProtos.Networking.Envelopes_pb2.RequestEnvelope()
  248. p_req.request_id = 1469378659230941192
  249.  
  250. p_req.status_code = POGOProtos.Networking.Envelopes_pb2.GET_PLAYER
  251.  
  252. p_req.latitude, p_req.longitude, p_req.altitude = (FLOAT_LAT, FLOAT_LNG, FLOAT_ALT)
  253.  
  254. p_req.unknown12 = 989 #transaction id, anything works
  255. if 'useauth' not in kw or not kw['useauth']:
  256. p_req.auth_info.provider = login_type
  257. p_req.auth_info.token.contents = access_token
  258. p_req.auth_info.token.unknown2 = 14
  259. else:
  260. p_req.auth_ticket.start = kw['useauth'].start
  261. p_req.auth_ticket.expire_timestamp_ms = kw['useauth'].expire_timestamp_ms
  262. p_req.auth_ticket.end = kw['useauth'].end
  263.  
  264. for meh in mehs:
  265. p_req.MergeFrom(meh)
  266. protobuf = p_req.SerializeToString()
  267. r = SESSION.post(api_endpoint, data=protobuf, verify=False)
  268.  
  269. retry_after=1
  270. while r.status_code!=200:
  271. print('[-] Connection error {}, retrying in {} seconds'.format(r.status_code,retry_after))
  272. time.sleep(retry_after)
  273. retry_after=min(retry_after*2,MAXWAIT)
  274. r = SESSION.post(api_endpoint, data=protobuf, verify=False)
  275.  
  276. p_ret = POGOProtos.Networking.Envelopes_pb2.ResponseEnvelope()
  277. p_ret.ParseFromString(r.content)
  278. return p_ret
  279.  
  280. except Exception,e:
  281. print('[-] Uncaught connection error, error: {}'.format(e))
  282. if r is not None:
  283. print('[-] Uncaught connection error, http code: {}'.format(r.status_code))
  284. else:
  285. print('[-] Error happened before network request.')
  286. print('[-] Retrying...')
  287. time.sleep(2)
  288.  
  289. def get_profile(access_token, api, useauth, *reqq):
  290. req = POGOProtos.Networking.Envelopes_pb2.RequestEnvelope()
  291.  
  292. req1 = req.requests.add()
  293. req1.request_type = POGOProtos.Networking.Envelopes_pb2.GET_PLAYER
  294. if len(reqq) >= 1:
  295. req1.MergeFrom(reqq[0])
  296.  
  297. req2 = req.requests.add()
  298. req2.request_type = POGOProtos.Networking.Envelopes_pb2.GET_HATCHED_EGGS
  299. if len(reqq) >= 2:
  300. req2.MergeFrom(reqq[1])
  301.  
  302. req3 = req.requests.add()
  303. req3.request_type = POGOProtos.Networking.Envelopes_pb2.GET_INVENTORY
  304. if len(reqq) >= 3:
  305. req3.MergeFrom(reqq[2])
  306.  
  307. req4 = req.requests.add()
  308. req4.request_type = POGOProtos.Networking.Envelopes_pb2.CHECK_AWARDED_BADGES
  309. if len(reqq) >= 4:
  310. req4.MergeFrom(reqq[3])
  311.  
  312. req5 = req.requests.add()
  313. req5.request_type = POGOProtos.Networking.Envelopes_pb2.DOWNLOAD_SETTINGS
  314. if len(reqq) >= 5:
  315. req5.MergeFrom(reqq[4])
  316.  
  317. newResponse = api_req(api, access_token, req, useauth = useauth)
  318.  
  319. retry_after=1
  320. while (newResponse.status_code not in [1,2,53,102]): #1 for hearbeat, 2 for profile authorization, 53 for api endpoint, 52 for error, 102 session token invalid
  321. print('[-] Response error, status code: {}, retrying in {} seconds'.format(newResponse.status_code,retry_after))
  322. time.sleep(retry_after)
  323. retry_after=min(retry_after*2,MAXWAIT)
  324. newResponse = api_req(api, access_token, req, useauth = useauth)
  325.  
  326. return newResponse
  327.  
  328. def set_api_endpoint():
  329. global api_endpoint
  330. p_ret = get_profile(access_token, API_URL, None)
  331. while p_ret.status_code==102:
  332. print('[-] Error, invalid session, retrying...')
  333. time.sleep(300) #at that point the severs are pretty much done for, so waiting for 5 min
  334. p_ret = get_profile(access_token, API_URL, None)
  335.  
  336. api_endpoint = ('https://%s/rpc' % p_ret.api_url)
  337.  
  338. def authorize_profile():
  339. global response
  340. response = get_profile(access_token, api_endpoint, None)
  341.  
  342. def heartbeat():
  343. while True:
  344. lastR_t = int(time.time()*1000)
  345. m5 = POGOProtos.Networking.Envelopes_pb2.RequestEnvelope().requests.add()
  346. #m5.request_type = POGOProtos.Networking.Envelopes_pb2.DOWNLOAD_SETTINGS
  347. m51 = POGOProtos.Networking.Requests.Messages_pb2.DownloadSettingsMessage()
  348. m51.hash = "05daf51635c82611d1aac95c0b051d3ec088a930"
  349. m5.request_message = m51.SerializeToString()
  350.  
  351. m4 = POGOProtos.Networking.Envelopes_pb2.RequestEnvelope().requests.add()
  352. #m4.request_type = POGOProtos.Networking.Envelopes_pb2.CHECK_AWARDED_BADGES
  353. #m41 = POGOProtos.Networking.Requests.Messages_pb2.CheckAwardedBadgesMessage()
  354.  
  355.  
  356. m3 = POGOProtos.Networking.Envelopes_pb2.RequestEnvelope().requests.add()
  357. #m3.request_type = POGOProtos.Networking.Envelopes_pb2.GET_INVENTORY
  358. m31 = POGOProtos.Networking.Requests.Messages_pb2.GetInventoryMessage()
  359. m31.last_timestamp_ms = lastR_t
  360. m3.request_message = m31.SerializeToString()
  361.  
  362.  
  363. m2 = POGOProtos.Networking.Envelopes_pb2.RequestEnvelope().requests.add()
  364. #m2.request_type = POGOProtos.Networking.Envelopes_pb2.GET_HATCHED_EGGS
  365. #m21 = POGOProtos.Networking.Requests.Messages_pb2.GetHatchedEggsMessage()
  366.  
  367.  
  368. m1 = POGOProtos.Networking.Envelopes_pb2.RequestEnvelope().requests.add()
  369. m1.request_type = POGOProtos.Networking.Envelopes_pb2.GET_MAP_OBJECTS
  370. m11 = POGOProtos.Networking.Requests.Messages_pb2.GetMapObjectsMessage()
  371.  
  372. walk = sorted(getNeighbors())
  373. m11.cell_id.extend(walk)
  374.  
  375. m11.since_timestamp_ms.extend([0]*len(walk))
  376. m11.latitude = FLOAT_LAT
  377. m11.longitude = FLOAT_LNG
  378. m1.request_message = m11.SerializeToString()
  379. newResponse = get_profile(access_token, api_endpoint, response.auth_ticket, m1, m2, m3, m4, m5)
  380. if newResponse.status_code==1:
  381. payload = newResponse.returns[0]
  382. heartbeat = POGOProtos.Networking.Responses_pb2.GetMapObjectsResponse()
  383. heartbeat.ParseFromString(payload)
  384. return heartbeat
  385. elif newResponse.status_code==2:
  386. authorize_profile()
  387. elif newResponse.status_code==102:
  388. print('[-] Error, refreshing login')
  389. do_login()
  390. set_api_endpoint()
  391. authorize_profile()
  392. else:
  393. print('[-] Heartbeat error, status code: {}'.format(newResponse.status_code)) #should not happen, probably unused
  394. print('[-] Retrying...')
  395. time.sleep(2)
  396.  
  397. def fixNum(int_type):
  398. length = 0
  399. int_ret = ~int_type
  400. while (int_ret):
  401. int_ret >>= 1
  402. length += 1
  403. int_ret = int_type ^ (-1 << length)
  404. int_ret = int_ret-0x1A000
  405. return int_ret
  406.  
  407. def main():
  408. global wID
  409. global li_user
  410. global li_password
  411. global HEX_NUM
  412. global MAXWAIT
  413. interval=0
  414. parser = argparse.ArgumentParser()
  415. parser.add_argument("-id", "--id", help="worker id")
  416. parser.add_argument("-r", "--range", help="scan range")
  417. parser.add_argument("-t", "--timeinterval", help="time interval")
  418. parser.set_defaults(id=0,range=20,timeinterval=300)
  419.  
  420. args = parser.parse_args()
  421.  
  422. if args.id is not None:
  423. wID=int(args.id)
  424. if wID < 0 or wID > 6:
  425. raise TypeError('id must be positive')
  426.  
  427. if args.range is not None:
  428. HEX_NUM=int(args.range)
  429. if HEX_NUM < 0 or HEX_NUM > 100:
  430. raise TypeError('range must be between 0 and 100, recommended: 20')
  431.  
  432. if args.timeinterval is not None:
  433. interval=int(args.timeinterval)
  434. if interval < 0 or interval > 900:
  435. raise TypeError('time interval must be between 0 and 900, recommended 600')
  436.  
  437. DATA_FILE = 'res/data{}.json'.format(wID)
  438. STAT_FILE = 'res/spawns{}.json'.format(wID)
  439.  
  440. pokemons = json.load(open('res/'+LANGUAGE+'.json'))
  441. init_location()
  442.  
  443. do_login()
  444.  
  445. print('[+] RPC Session Token: {}'.format(access_token))
  446.  
  447. set_api_endpoint()
  448. print('[+] API endpoint: {}'.format(api_endpoint))
  449. authorize_profile()
  450. print('[+] Login successful')
  451.  
  452. payload = response.returns[0]
  453. profile = POGOProtos.Networking.Responses_pb2.GetPlayerResponse()
  454. profile.ParseFromString(payload)
  455.  
  456. print('[+] Username: {}'.format(profile.player_data.username))
  457.  
  458. creation_time = datetime.fromtimestamp(int(profile.player_data.creation_timestamp_ms)/1000)
  459. print('[+] You are playing Pokemon Go since: {}'.format(creation_time.strftime('%Y-%m-%d %H:%M:%S')))
  460. for curr in profile.player_data.currencies:
  461. print('[+] {}: {}'.format(curr.name, curr.amount))
  462.  
  463. MAXWAIT=NET_MAXWAIT
  464. origin = LatLng.from_degrees(FLOAT_LAT, FLOAT_LNG)
  465. all_ll = [origin]
  466. maxR = 1;
  467. for a in range(1,HEX_NUM+1):
  468. for i in range(0,a*6):
  469. latrad = origin.lat().radians
  470.  
  471. x_un=1.5*HEX_R/getEarthRadius(latrad)/math.cos(latrad)*safety*180/math.pi
  472. y_un=1.0*HEX_M/getEarthRadius(latrad)*safety*180/math.pi
  473. if i < a:
  474. lat = FLOAT_LAT+y_un*(-2*a+i)
  475. lng = FLOAT_LNG+x_un*i
  476. elif i < 2*a:
  477. lat = FLOAT_LAT+y_un*(-3*a+2*i)
  478. lng = FLOAT_LNG+x_un*a
  479. elif i < 3*a:
  480. lat = FLOAT_LAT+y_un*(-a+i)
  481. lng = FLOAT_LNG+x_un*(3*a-i)
  482. elif i < 4*a:
  483. lat = FLOAT_LAT+y_un*(5*a-i)
  484. lng = FLOAT_LNG+x_un*(3*a-i)
  485. elif i < 5*a:
  486. lat = FLOAT_LAT+y_un*(9*a-2*i)
  487. lng = FLOAT_LNG+x_un*-a
  488. else:
  489. lat = FLOAT_LAT+y_un*(4*a-i)
  490. lng = FLOAT_LNG+x_un*(-6*a+i)
  491.  
  492. all_ll.append(LatLng.from_degrees(lat,lng))
  493. maxR+=1;
  494.  
  495. #/////////////////
  496.  
  497. #////////////////////
  498. print('')
  499. try:
  500. f=open(STAT_FILE,'a')
  501. if f.tell()==0:
  502. f.write('Name\tid\tSpawnID\tlat\tlng\tspawnTime\tTime\tTime2Hidden\tencounterID\n')
  503. finally:
  504. f.close()
  505. seen = set([])
  506. uniqueE = set([])
  507. while True:
  508. curT=int(time.time())
  509. #curR=0;
  510. print("[+] Time: " + datetime.now().strftime("%H:%M:%S"))
  511. for this_ll in all_ll:
  512. #if LOGGING:
  513. #print('[+] Finished: '+str(100.0*curR/maxR)+' %')
  514. #curR+=1
  515. set_location_coords(this_ll.lat().degrees, this_ll.lng().degrees, ALT_C)
  516. h = heartbeat()
  517. try:
  518. f= open(STAT_FILE,'a',1)
  519. for cell in h.map_cells:
  520. for wild in cell.wild_pokemons:
  521. if (wild.encounter_id not in seen):
  522. seen.add(wild.encounter_id)
  523. if (wild.encounter_id not in uniqueE):
  524. spawnIDint=int(wild.spawn_point_id, 16)
  525. org_tth=wild.time_till_hidden_ms
  526. if wild.time_till_hidden_ms < 0:
  527. wild.time_till_hidden_ms=901000
  528. else:
  529. uniqueE.add(wild.encounter_id)
  530.  
  531. f.write('{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\n'.format(pokemons[wild.pokemon_data.pokemon_id],wild.pokemon_data.pokemon_id,spawnIDint,wild.latitude,wild.longitude,(wild.last_modified_timestamp_ms+wild.time_till_hidden_ms)/1000.0-900.0,wild.last_modified_timestamp_ms/1000.0,org_tth/1000.0,wild.encounter_id))
  532. add_pokemon(wild.pokemon_data.pokemon_id,spawnIDint, wild.latitude, wild.longitude, int((wild.last_modified_timestamp_ms+wild.time_till_hidden_ms)/1000.0))
  533.  
  534. if LOGGING:
  535. other = LatLng.from_degrees(wild.latitude, wild.longitude)
  536. diff = other - origin
  537. difflat = diff.lat().degrees
  538. difflng = diff.lng().degrees
  539. direction = (('N' if difflat >= 0 else 'S') if abs(difflat) > 1e-4 else '') + (('E' if difflng >= 0 else 'W') if abs(difflng) > 1e-4 else '')
  540. print("<<>> (%s) %s visible for %s seconds (%sm %s from you)" % (wild.pokemon_data.pokemon_id, pokemons[wild.pokemon_data.pokemon_id], int(wild.time_till_hidden_ms/1000.0), int(origin.get_distance(other).radians * 6366468.241830914), direction))
  541. finally:
  542. f.close()
  543. write_data_to_file(DATA_FILE)
  544. #if LOGGING:
  545. #print('')
  546. #time.sleep(1)
  547. uniqueE=uniqueE & seen
  548. seen.clear()
  549. curT = int(time.time())-curT
  550. print('[+] Scan Time: {} s'.format(curT))
  551. curT=max(interval-curT,0)
  552. print('[+] Sleeping for {} seconds...'.format(curT))
  553. time.sleep(curT)
  554. prune_data()
  555. if __name__ == '__main__':
  556. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement