Beispiel #1
0
def submit(request):
	if request.method == 'POST':
		form = LocationForm(request.POST)
		if form.is_valid():
			user_need = form.cleaned_data
			ip = request.META['HTTP_X_FORWARDED_FOR'] if not TEST else "67.169.27.214"
			if user_need['coordinates'] == 'current':
				coord = cache.get(ip)
				if coord:
					lat, lon = getLatLong(coord)
				else: # in case the cache failed
					coord = getCoord(request)
					lat, lon = getLatLong(coord)
					logging.error('using api to get coord --- cache failed')
			else:
				lat, lon = getLatLong(user_need['coordinates'])
			class_id = int(user_need['parktype'])
			resList = recommend.recommend(class_id, lat, lon)
			res = resList[1]["result"]
			resN = resList[0]["result"][0]
			NweatherList = weather.getWeather(str(resN['coords']['lat']), str(resN['coords']['lon']))
			resN['weather'] = NweatherList
			resDetail = getResDetail(res)
			API_KEY = 'AIzaSyAnEt9j1iiUDG6X2cRxQ2GUfotwoe4vCCY'
			google_maps = "https://maps.googleapis.com/maps/api/js?key="+API_KEY+"&sensor=false"
			content = {'results': resDetail,
			           'Nresult': resN,
					   'google_maps_src': google_maps ,
		               'latitude' : lat,
		               'longitude' : lon,
		               'lat0': float(resN['coords']['lat']),
		               'lon0': float(resN['coords']['lon'])
		               }
			return render(request, 'mainpage/recommend.html', content)
Beispiel #2
0
def submit(request):
	if request.method == 'POST':
		urlfetch.set_default_fetch_deadline(10)
		form = LocationForm(request.POST)
		if form.is_valid():
			user_need = form.cleaned_data
			if test == False:
				ra = 'REMOTE_ADDR'
				ip = request.META[ra]
			else:
				ip = memcache.get('ip')
			# logging.error(ip)
			if user_need['coordinates'] == 'current':
				coord = memcache.get(ip)
				lat, lon = getLatLong(coord)
				logging.error('default coord')
				logging.error(coord)
			else:
				lat, lon = getLatLong(user_need['coordinates'])
			class_id = int(user_need['parktype'])
			res = recommender.recommend(class_id, lat, lon)
			resN = recommender.recommendN(class_id, lat, lon)
			NweatherList = weather.getWeather(str(resN['coords']['lat']), str(resN['coords']['lon']))
			resN['weather'] = NweatherList
			resDetail = getResDetail(res)
			API_KEY = 'AIzaSyAnEt9j1iiUDG6X2cRxQ2GUfotwoe4vCCY'
			google_maps = "https://maps.googleapis.com/maps/api/js?key="+API_KEY+"&sensor=false"
			content = {'results': resDetail,
			           'Nresult': resN,
					   'google_maps_src': google_maps ,
		               'latitude' : lat,
		               'longitude' : lon,
		               'lat0': float(resN['coords']['lat']),
		               'lon0': float(resN['coords']['lon']),
		               'lat1': float(res[0]['latitude']),
		               'lon1': float(res[0]['longitude']),
		               'lat2': float(res[1]['latitude']),
		               'lon2': float(res[1]['longitude']),
		               'lat3': float(res[2]['latitude']),
		               'lon3': float(res[2]['longitude'])
		               }
			return render(request, 'mainpage/recommend.html', content)