Zeroji

Untitled

Sep 9th, 2015
77
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #qpy:2
  2. #qpy:console
  3.  
  4. #import androidhelper as android
  5. import time, urllib2, math
  6.  
  7. def glt():
  8. return time.localtime()
  9.  
  10. def dtr(d):
  11. return d*3.1415926535/180
  12.  
  13. def dist(la, lo, lat, lon):
  14. r=6371000
  15. dla = dtr(lat-la)
  16. dlo = dtr(lon-lo)
  17.  
  18. a = math.sin(dla/2)**2 + math.cos(dtr(la))*math.cos(dtr(lat)) * math.sin(dlo/2)**2
  19.  
  20. c = 2 * math.atan2(a**0.5, (1-a)**0.5)
  21. return r * c
  22.  
  23. def secs(hhmmss):
  24. return 3600*int(hhmmss[0:2])+60*int(hhmmss[3:5])+int(hhmmss[6:8])
  25.  
  26. def hms(secs):
  27. h, m, s = secs/3600, (secs%3600)/60, secs%60
  28. return str(h/10)+str(h%10)+':'+str(m/10)+str(m%10)+':'+str(s/10)+str(s%10)
  29.  
  30. def isv(serv):
  31. lt = glt()
  32. return isAv(serv, str(lt[0])+str(lt[1]/10)+str(lt[1]%10)+str(lt[2]/10)+str(lt[2]%10), lt[6]);
  33.  
  34. def isAv(serv, date, dow): # date is 'YYYYMMAA' # dow is from Mon 0
  35. s=sum([s[2] for s in cd if s[0]==serv and s[1]==date])
  36. if s>0: return s==1
  37. date = int(date)
  38. return sum([int(s[dow+1]) for s in cl if s[0]==serv and date>=int(s[8]) and date<=int(s[9])])>0
  39.  
  40.  
  41. print 'Loading files...'
  42. droot = '/storage/emulated/0/Download/Tan/'
  43. droot = 'Documents/Tan/'
  44. st = [s.split(',') for s in open(droot+'stops.txt').readlines()[1:]]
  45. ts = [s.split(',') for s in open(droot+'stop_times.txt').readlines()[1:]]
  46. tr = [s.split(',') for s in open(droot+'trips.txt').readlines()[1:]]
  47. rt = [s.split(',') for s in open(droot+'routes.txt').readlines()[1:]]
  48. cl = [s.split(',') for s in open(droot+'calendar.txt').readlines()[1:]]
  49. cd = [s.split(',') for s in open(droot+'calendar_dates.txt').readlines()[1:]]
  50.  
  51. pt = [s for s in st if s[7]=='0']
  52. st = [s for s in st if s[7]=='1']
  53. print 'Setup complete!'
  54. # stops, times, trips, routes, points
  55. gps = False
  56. home= False
  57. loop= True
  58.  
  59. while loop:
  60. found = False
  61. if gps:
  62. time.sleep(2)
  63. droid=android.Android()
  64. droid.startLocating()
  65. event=droid.eventWaitFor('location', 10000).result
  66. try:
  67. lng = -1.55716847 if home else -1.51530761
  68. lat = 47.25072151 if home else 47.28189980
  69. if gps:
  70. lng = event['data']['gps']['longitude']
  71. lat = event['data']['gps']['latitude']
  72. print "Lng: %s Lat: %s" %(lng,lat)
  73. found = True
  74. except:
  75. print "Network Coordinates"
  76. if found:
  77. prox = []
  78. for s in st[1:]:
  79. la = float(s[3])
  80. lo = float(s[4])
  81. nm = s[1]
  82. ds = dist(la, lo, lat, lng)
  83. prox.append((ds, nm[1:-1], s[0]))
  84. prox.sort()
  85. lt = glt()
  86. dow = lt[6] if lt[3]>3 else (lt[6]+6)%7
  87. now = 3600*lt[3]+60*lt[4]+lt[5]+(84600 if lt[3]<4 else 0)
  88. for i in range(8):
  89. stop=prox[i]
  90. print stop[1]+' ('+str(int(stop[0]))+'m)'
  91. if i<2:
  92. sts = [s[0] for s in pt if s[8]==stop[2]]
  93. pxr = [(secs(s[2])-now, s) for s in ts if s[3] in sts and secs(s[2])>now and secs(s[2])<=now+3600]
  94. pxr = [(p[0], p[1], [s for s in tr if s[2]==p[1][0]][0]) for p in pxr]
  95. prx = [(p[0], p[1], p[2], for p in pxr if isv(p[2][1]) ]
  96. print prx
  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. if not gps:
  126. time.sleep(3)
  127. loop=False
RAW Paste Data