Exemple #1
0
def find_therapist():
    """This function uses the Google Places API to recommend a therapist based on the user's location. """
    keyword = "counseling OR therapist OR psychiatrist"
    try:
        address = get_alexa_location()
        pass
    except:
        return statement(
            """Hmm. It appears that I can't find your location. Please allow access to your "
                         location in the Alexa app and try again """
        ).consent_card("read::alexa:device:all:address")
    g = geocoder.google(address)
    latlng = g.latlng
    location = "{},{}".format(latlng[0], latlng[1])
    print(location)
    key = "api_key"
    URL2 = "https://maps.googleapis.com/maps/api/place/textsearch/json?location={}&query={}&key={}".format(
        location, keyword, key)
    print(URL2)
    r2 = requests.get(URL2)
    if r2.status_code == 200:
        first_output = r2.json()
    else:
        return "Sorry, I'm having trouble doing that right now. Please try again later."
    results = first_output['results']
    idnum = (results[1]['place_id'])
    name = (results[1]['name'])
    # print(results[1])
    # print(idnum)
    URL3 = "https://maps.googleapis.com/maps/api/place/details/json?placeid={}&key={}".format(
        idnum, key)
    r3 = requests.get(URL3)
    if r3.status_code == 200:
        second_output = r3.json()
        phone = (second_output['result'])['international_phone_number']
        # print(second_output)
        # print(phone)
        session.attributes["State"] = "Null"
        message = """I've found a therapist near you. Their name is: {}, and their number is: {}. I've added their
        contact info to a card in the Alexa app. Is there anything else I can do?""".format(
            name, phone)
        card = "Name:{} \n Phone:{}".format(name, phone)
        return question(message).standard_card(
            title="I've found you a possible therapist",
            text=card,
            large_image_url=
            "https://images.unsplash.com/photo-1489533119213-66a5cd877091?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=7c006c52fd09caf4e97536de8fcf5067&auto=format&fit=crop&w=1051&q=80"
        )
    else:
        return statement(
            "Sorry, I'm having trouble doing that right now. Please try again later."
        )
Exemple #2
0
def find_therapist():
    """This function uses the Google Places API to recommend a therapist based on the user's location. """
    keyword = "counseling OR therapist OR psychiatrist"
    try:
        address = get_alexa_location()
        logging.debug(address)
        pass
    except:
        logging.error("COULD NOT GET ALEXA LOCATION")
        logging.debug(traceback.format_exc())
        return statement(
            """Hmm. It appears that I can't find your location. Please allow access to your
                         location in the Alexa app and try again """
        ).consent_card("read::alexa:device:all:address")
    try:
        gcodeurl = 'https://maps.googleapis.com/maps/api/geocode/json'
        params = {'sensor': 'false', 'address': address}
        gc = requests.get(gcodeurl, params=params, verify=False)
        results = gc.json()['results']
        location = results[0]['geometry']['location']
        location = "{},{}".format(location['lat'], location['lng'])
    except:
        logging.error('ERROR using google geocoder')
        logging.debug(gc.json())
        return statement(
            "Sorry, I'm having trouble doing that right now. Please try again later."
        )
    print(location)
    key = os.environ['GCLOUD_KEY']
    URL2 = "https://maps.googleapis.com/maps/api/place/textsearch/json?location={}&query={}&key={}".format(
        location, keyword, key)
    print(URL2)
    r2 = requests.get(URL2, verify=False)
    if r2.status_code == 200:
        first_output = r2.json()
    else:
        return "Sorry, I'm having trouble doing that right now. Please try again later."
    results = first_output['results']
    idnum = (results[1]['place_id'])
    name = (results[1]['name'])
    # print(results[1])
    # print(idnum)
    URL3 = "https://maps.googleapis.com/maps/api/place/details/json?placeid={}&key={}".format(
        idnum, key)
    r3 = requests.get(URL3, verify=False)
    if r3.status_code == 200:
        second_output = r3.json()
        phone = (second_output['result'])['international_phone_number']
        # print(second_output)
        # print(phone)
        session.attributes["State"] = "Null"
        message = """I've found a therapist near you.
        Their name is: {}, and their number is: {}. I've added their contact info to a card in the Alexa app.
         Is there anything else I can do?""".format(name, phone)
        card = "Name:{} \n Phone:{}".format(name, phone)
        return question(message).standard_card(
            title="I've found you a possible therapist",
            text=card,
            large_image_url=
            "https://images.unsplash.com/photo-1489533119213-66a5cd877091?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=7c006c52fd09caf4e97536de8fcf5067&auto=format&fit=crop&w=1051&q=80"
        )
    else:
        return statement(
            "Sorry, I'm having trouble doing that right now. Please try again later."
        )