Ejemplo n.º 1
0
def slash():
    if request.method == 'GET':
        form = NumberAddressForm()
        return render_template('slash.html', form=form)
    elif request.method == 'POST':
        form = NumberAddressForm(request.form)
        if form.validate():
            phone = ''.join(e for e in form.phone.data if e.isalnum())
            headers = {'Content-Type': 'application/json'}
            phone_endpoint = 'http://%s:%s/%s/' % (host, port, "phones")
            response = requests.get(phone_endpoint + phone, headers=headers)

            if response.status_code != 200:
                gmaps = googlemaps.Client(key=GOOGLE_API_KEY)
                directions = gmaps.directions(form.home_address.data, form.work_address.data, mode="driving")
                g = geocoders.GoogleV3(GOOGLE_API_KEY)
                home_location_geo = g.geocode(form.home_address.data)
                work_location_geo = g.geocode(form.work_address.data)
                data = form.data
                data['is_verified'] = False
                data["work_address_geo"] = {'type': 'Point', 'coordinates': [work_location_geo.longitude, work_location_geo.latitude]}
                data["home_address_geo"] = {'type': 'Point', 'coordinates': [home_location_geo.longitude, home_location_geo.latitude]}
                response = requests.post(phone_endpoint, json.dumps(data), headers=headers)
                decoded = decode_line(directions[0]["overview_polyline"]["points"])
                stuffs = []
                for decode in decoded:
                    stuffs.append({'phone': phone, 'location': {'type': 'Point', 'coordinates': [decode[1], decode[0]]}})

                route_endpoint = 'http://%s:%s/%s/' % (host, port, "routes")
                response = requests.post(route_endpoint, json.dumps(stuffs), headers=headers)
                return render_template('success.html')
            else:
                return render_template('already_registered.html')
        return render_template('slash.html', form=form)
Ejemplo n.º 2
0
def venues():
    category = request.args.get('category')
    encoded = request.args.get('polyline')
    decoded = decode_line(encoded)

    clientID = secrets.get("foursquare", "clientID")
    clientSecret = secrets.get("foursquare", "clientSecret")

    session = FuturesSession()
    reqs = []
    for waypt in decoded[0::20]:
        reqs.append(
            getVenuesNearLocation(waypt, category, clientID, clientSecret,
                                  session))

    allVenues = []
    ids = []  #<- for uniquing
    for req in reqs:
        response = req.result()
        json = response.json()
        venues = [
            item["venue"] for item in json["response"]["groups"][0]["items"]
            if item["venue"]["id"] not in ids
        ]
        ids.extend([venue["id"] for venue in venues])
        allVenues.extend(venues)
    return jsonify({"venues": allVenues})
Ejemplo n.º 3
0
def slash():
    if request.method == 'GET':
        form = NumberAddressForm()
        return render_template('slash.html', form=form)
    elif request.method == 'POST':
        form = NumberAddressForm(request.form)
        if form.validate():
            phone = ''.join(e for e in form.phone.data if e.isalnum())
            headers = {'Content-Type': 'application/json'}
            phone_endpoint = 'http://%s:%s/%s/' % (host, port, "phones")
            response = requests.get(phone_endpoint + phone, headers=headers)

            if response.status_code != 200:
                gmaps = googlemaps.Client(key=GOOGLE_API_KEY)
                directions = gmaps.directions(form.home_address.data,
                                              form.work_address.data,
                                              mode="driving")
                g = geocoders.GoogleV3(GOOGLE_API_KEY)
                home_location_geo = g.geocode(form.home_address.data)
                work_location_geo = g.geocode(form.work_address.data)
                data = form.data
                data['is_verified'] = False
                data["work_address_geo"] = {
                    'type':
                    'Point',
                    'coordinates':
                    [work_location_geo.longitude, work_location_geo.latitude]
                }
                data["home_address_geo"] = {
                    'type':
                    'Point',
                    'coordinates':
                    [home_location_geo.longitude, home_location_geo.latitude]
                }
                response = requests.post(phone_endpoint,
                                         json.dumps(data),
                                         headers=headers)
                decoded = decode_line(
                    directions[0]["overview_polyline"]["points"])
                stuffs = []
                for decode in decoded:
                    stuffs.append({
                        'phone': phone,
                        'location': {
                            'type': 'Point',
                            'coordinates': [decode[1], decode[0]]
                        }
                    })

                route_endpoint = 'http://%s:%s/%s/' % (host, port, "routes")
                response = requests.post(route_endpoint,
                                         json.dumps(stuffs),
                                         headers=headers)
                return render_template('success.html')
            else:
                return render_template('already_registered.html')
        return render_template('slash.html', form=form)
Ejemplo n.º 4
0
def directions():
	waypoints = request.args.get('waypoints').split('|')
	params = {"origin": waypoints[0],
		 "destination": waypoints[-1],
		 	  "sensor": "true"}
	if len(waypoints) > 2:
		params["waypoints"] = "optimize:true|" + "|".join(waypoints[1:-1])
	r = requests.get(googBaseURL + '/directions' + format, params=params)

	polyline = r.json()["routes"][0]["overview_polyline"]["points"]
	decoded = decode_line(polyline)
	formatted = [{"lat": tup[0], "lng": tup[1]} for tup in decoded]
	return jsonify({"polyline": formatted, "encoded": polyline})
Ejemplo n.º 5
0
def directions():
    waypoints = request.args.get('waypoints').split('|')
    params = {
        "origin": waypoints[0],
        "destination": waypoints[-1],
        "sensor": "true"
    }
    if len(waypoints) > 2:
        params["waypoints"] = "optimize:true|" + "|".join(waypoints[1:-1])
    r = requests.get(googBaseURL + '/directions' + format, params=params)

    polyline = r.json()["routes"][0]["overview_polyline"]["points"]
    decoded = decode_line(polyline)
    formatted = [{"lat": tup[0], "lng": tup[1]} for tup in decoded]
    return jsonify({"polyline": formatted, "encoded": polyline})
Ejemplo n.º 6
0
def venues():
	category = request.args.get('category')
	encoded = request.args.get('polyline')
	decoded = decode_line(encoded)

	clientID = secrets.get("foursquare", "clientID")
	clientSecret = secrets.get("foursquare", "clientSecret")

	session = FuturesSession()
	reqs = []
	for waypt in decoded[0::20]:
		reqs.append(getVenuesNearLocation(waypt, category, clientID, clientSecret, session))
	
	allVenues = []
	ids = []   #<- for uniquing 
	for req in reqs:
		response = req.result()
		json = response.json()
		venues = [item["venue"] for item in json["response"]["groups"][0]["items"]
					if item["venue"]["id"] not in ids]
		ids.extend([venue["id"] for venue in venues])
		allVenues.extend(venues)
	return jsonify({"venues": allVenues})