In [216]:
import requests
import json
import random
This was created during the Hack Auckland: Auckland Transport event in Auckland. The first day was spent visiting the vendors and having a play with bitcoin. 2nd day was more productive with this python code being typed. My plan was to use data from the Auckland Motorcams to detect crashes or events happening on the road. I really should of said this when I got up and talked in front of people about my plan for the event - instead I mentioned the camera feed and how I would like to improve it with more relatient information - including gps of the cameras.
In [217]:
atdat = requests.get('https://api.at.govt.nz/v1/public/display/parkinglocations?api_key=433feddb-d4b9-473b-a0c2-ac982a6d78cd')
In [218]:
atext = atdat.text
In [219]:
atdict = json.loads(atext)
In [220]:
atres = atdict['response']
In [221]:
atlen = len(atres)
In [222]:
ranpark = random.randint(0, atlen)
In [223]:
mything = parks()
In [256]:
for a in mything.getparks():
print a.keys()
In [226]:
blen = atres[0:atlen]
In [227]:
ranitem = test.ranpark()
In [229]:
thekeys = ranitem.keys()
In [230]:
thekeys
In [231]:
listz = []
In [257]:
for kez in thekeys:
#print key
print atres[0][kez]
listz.append(atres[0][kez])
In [233]:
#dait = atdict.items()
In [234]:
print listz[3]
In [235]:
import geopy
In [236]:
geo = geopy.GoogleV3()
In [237]:
geo.geocode(listz[3])
In [238]:
olenz = len(listz)
In [239]:
dachoice = random.randint(0, olenz)
In [240]:
dachoice
Out[240]:
In [241]:
class parks(object):
def getparks(self):
return atres
def items(self):
return atres[0]
def ranpark(self):
return atres[ranpark]
def genpark(self):
return (geo.geocode(listz[3]))
def parkloc(self):
return(atres[ranpark]['address'])
def parkid(self):
return(atres[renpark]['id'])
def parkcheck():
return(atres[renpark]['type'])
def parknon(self, inpuz ):
return(atres[renpark][inpuz])
In [241]:
In [242]:
park = parks()
In [243]:
park.genpark()
In [244]:
park.parkloc()
park.parknon()
In [245]:
park.parkid()
In [246]:
test.geopark()
In [247]:
geo.geocode(listz[3])
In [248]:
listz.sort()
In [249]:
listz
Out[249]:
In [ ]:
#atdict.viewkeys()
In [ ]:
#atrespon = atdict['response']
In [ ]:
In [ ]:
#savdict = open('/home/wcmckee/pyatakl/tests/presets/carparks.json', 'w')
#savdict.write(str(atdict))
In [ ]:
#dait
In [ ]:
In [ ]:
#atdict.values()
In [ ]:
#for d in blen:
# print d['address']
In [ ]:
#print atext
In [ ]:
In [ ]:
#atke
In [ ]:
#atkey.name
In [ ]:
In [258]:
getdispl = ('http://api.at.govt.nz/v1/public/realtime/vehiclelocations?api_key=433feddb-d4b9-473b-a0c2-ac982a6d78cd')
In [259]:
getres = requests.get(getdispl)
In [260]:
gettx = getres.text
In [261]:
pajson = json.loads(gettx)
In [262]:
patza = pajson.keys()
In [263]:
pajson.keys()
Out[263]:
In [264]:
for i in pajson:
print i
In [265]:
patze = pajson['response']['entity'][0]
In [266]:
patze
Out[266]:
In [267]:
paveh = patze['vehicle']
In [268]:
pala = paveh['position']
In [269]:
print pala
In [270]:
palat = pala['latitude']
In [271]:
palat
Out[271]:
In [272]:
palong = pala['longitude']
In [273]:
palong
Out[273]:
In [274]:
class busdata(object):
def latdata(self):
return palat
def longdata(self):
return palong
In [275]:
busdata = busdata()
In [276]:
busdata.longdata()
Out[276]:
In [277]:
longdatas = str(busdata.longdata())
In [278]:
longdatas
Out[278]:
In [279]:
latdatas = str(busdata.latdata())
In [280]:
latdatas
Out[280]:
In [281]:
busdata.latdata()
Out[281]:
In [282]:
bothdata
Out[282]:
In [284]:
from geopy.geocoders import GoogleV3
geolocator = GoogleV3()
In [285]:
address, (longdatas, longitude) = geolocator.reverse(longdatas, latdatas)
print(address, latitude, longitude)
In [287]:
print geolocator.reverse(longdatas, latdatas)
In [289]:
print geolocator.geocode(latdatas, longdatas)
In [293]:
for d in geolocator.geocode(busdata.latdata(), busdata.longdata()):
print d
In [298]:
testgeo = geolocator.geocode(-36.921086, 174.80408)
In [300]:
print testgeo
In [ ]: