def new_property(request): # If the user is submitting the form if request.method == "POST": # Get the instance of the form filled with the submitted data # form = PropertyForm(request.POST) form = PropertyForm(request.POST, request.FILES) # Django will check the form's validity for you if form.is_valid(): # Saving the form will create a new Property object if form.save(): data = form.cleaned_data property_address = data['address'] google_maps = GoogleMaps(api_key='AIzaSyDlHBtlOb1-JpUPZ8CHAZqaNha6Uw_l_ow') location_info = google_maps.query(location=property_address) location_info = location_info.first() Property.objects.filter(address=property_address).update(xcoordinate=location_info.lat) Property.objects.filter(address=property_address).update(ycoordinate=location_info.lng) # After saving, redirect the user to add propertynotes return redirect("new_propertynotes") # Else if the user is looking at the form page else: form = PropertyForm() data = {'form': form} return render(request, "properties/add_property.html", data)
def map(request): #all_locations = Location.objects.all() address = "225 Bush Street San Francisco California" google_maps = GoogleMaps(api_key='AIzaSyDlHBtlOb1-JpUPZ8CHAZqaNha6Uw_l_ow') location_info = google_maps.query(location=address) location_info = location_info.first() data = {"location_info":location_info} return render(request, "map.html", data)
def new_property(request): s3_url = "https://homedbbucket.s3.amazonaws.com/" # If the user is submitting the form if request.method == "POST": # Get the instance of the form filled with the submitted data form = PropertyForm(request.POST, request.FILES) # Django will check the form's validity if form.is_valid(): # Saving the form will create a new Property object if form.save(): data = form.cleaned_data #using property address to lat and lng info from google map, then update table property_address = data['address'] google_maps = GoogleMaps(api_key=GOOGLE_API_KEY) location_info = google_maps.query(location=property_address) location_info = location_info.first() Property.objects.filter(address=property_address).update(xcoordinate=location_info.lat) Property.objects.filter(address=property_address).update(ycoordinate=location_info.lng) # After saving, redirect the user to add propertynotes return redirect("/properties/") else: print "not saved" else: print "form not valid" # Else if the user is looking at the form page else: form = PropertyForm() print "post failed" #S3 bucket data = {'form': form, 's3_url': s3_url} return render(request, "properties/add_property.html", data)
data.append(str(thing)) # table = parcelSoup.find(id='MainContent_ctl01_grdCns') # for row in table.findAll("tr"): # cells = row.findAll("td") # for el in cells:#this is a way of at looking at everyother cell thereby scraping only the right side of the table. # if i%2 == 0: # thing = el.string # if thing == '\xc2\xa0': # thing = '' # data.append(str(thing)) # i += 1 # categories.append(str(el.string)) #use this to append the long list of attributes in the table to catagories. Set i==2 address = parcelSoup.find(id="MainContent_lblLocation").string time.sleep(1) #the webstie does say to dissallow robots. This is a concesion to that. fullAddress = str(address + ', ' + city + ', ' + state) location = google_maps.query(location=fullAddress).first() time.sleep(1) data.append(location.lat) data.append(location.lng) data.append(parcelBaseURL) f.writerow(data) print location.lat print address address = None location.lat = None location.lng = None location = None data = None
# -- coding: utf-8 -- from geolocation.google_maps import GoogleMaps address = 'New York City Wall Street 12' google_maps = GoogleMaps(api_key='AIzaSyCqBaEO3JOEwpdTb31ImhXBU6t_7KBJWT8') location_info = google_maps.query(location=address) print location_info.all() # return list of all location. location_info = location_info.first() # return only first location. print location_info.city print location_info.route print location_info.street_number print location_info.country print location_info.lat print location_info.lng