Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #qpy:2
- #qpy:console
- #import androidhelper as android
- import time, urllib2, math
- def glt():
- return time.localtime()
- def dtr(d):
- return d*3.1415926535/180
- def dist(la, lo, lat, lon):
- r=6371000
- dla = dtr(lat-la)
- dlo = dtr(lon-lo)
- a = math.sin(dla/2)**2 + math.cos(dtr(la))*math.cos(dtr(lat)) * math.sin(dlo/2)**2
- c = 2 * math.atan2(a**0.5, (1-a)**0.5)
- return r * c
- def secs(hhmmss):
- return 3600*int(hhmmss[0:2])+60*int(hhmmss[3:5])+int(hhmmss[6:8])
- def hms(secs):
- h, m, s = secs/3600, (secs%3600)/60, secs%60
- return str(h/10)+str(h%10)+':'+str(m/10)+str(m%10)+':'+str(s/10)+str(s%10)
- def isv(serv):
- lt = glt()
- return isAv(serv, str(lt[0])+str(lt[1]/10)+str(lt[1]%10)+str(lt[2]/10)+str(lt[2]%10), lt[6]);
- def isAv(serv, date, dow): # date is 'YYYYMMAA' # dow is from Mon 0
- s=sum([s[2] for s in cd if s[0]==serv and s[1]==date])
- if s>0: return s==1
- date = int(date)
- 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
- print 'Loading files...'
- droot = '/storage/emulated/0/Download/Tan/'
- droot = 'Documents/Tan/'
- st = [s.split(',') for s in open(droot+'stops.txt').readlines()[1:]]
- ts = [s.split(',') for s in open(droot+'stop_times.txt').readlines()[1:]]
- tr = [s.split(',') for s in open(droot+'trips.txt').readlines()[1:]]
- rt = [s.split(',') for s in open(droot+'routes.txt').readlines()[1:]]
- cl = [s.split(',') for s in open(droot+'calendar.txt').readlines()[1:]]
- cd = [s.split(',') for s in open(droot+'calendar_dates.txt').readlines()[1:]]
- pt = [s for s in st if s[7]=='0']
- st = [s for s in st if s[7]=='1']
- print 'Setup complete!'
- # stops, times, trips, routes, points
- gps = False
- home= False
- loop= True
- while loop:
- found = False
- if gps:
- time.sleep(2)
- droid=android.Android()
- droid.startLocating()
- event=droid.eventWaitFor('location', 10000).result
- try:
- lng = -1.55716847 if home else -1.51530761
- lat = 47.25072151 if home else 47.28189980
- if gps:
- lng = event['data']['gps']['longitude']
- lat = event['data']['gps']['latitude']
- print "Lng: %s Lat: %s" %(lng,lat)
- found = True
- except:
- print "Network Coordinates"
- if found:
- prox = []
- for s in st[1:]:
- la = float(s[3])
- lo = float(s[4])
- nm = s[1]
- ds = dist(la, lo, lat, lng)
- prox.append((ds, nm[1:-1], s[0]))
- prox.sort()
- lt = glt()
- dow = lt[6] if lt[3]>3 else (lt[6]+6)%7
- now = 3600*lt[3]+60*lt[4]+lt[5]+(84600 if lt[3]<4 else 0)
- for i in range(8):
- stop=prox[i]
- print stop[1]+' ('+str(int(stop[0]))+'m)'
- if i<2:
- sts = [s[0] for s in pt if s[8]==stop[2]]
- 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]
- pxr = [(p[0], p[1], [s for s in tr if s[2]==p[1][0]][0]) for p in pxr]
- prx = [(p[0], p[1], p[2], for p in pxr if isv(p[2][1]) ]
- print prx
- if not gps:
- time.sleep(3)
- loop=False
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement