示例#1
0
def trigger_yelp(resp, sender_info):
    print("Pre Sender_Info: " + str(sender_info))
    sender_info = mongo.message_records.find_one(
        {"sms_id": sender_info['sms_id']})
    current_user = mongo.user_records.find_one({"phone": sender_info['from']})
    time.sleep(1)
    print("Yelp Triggered")
    print("Sender Info: " + str(sender_info))
    # print(resp)
    try:
        location = resp['entities']['location'][0]['value']
    except BaseException:
        try:
            location = resp['entities']['wit_home'][0]['value']
            location = current_user['home']
        except BaseException:
            try:
                location = location = resp['entities'][
                    'wikipedia_search_query'][0]['value']
            except BaseException:
                location = current_user['home']
    try:
        category = resp['entities']['wit_yelp_category'][0]['value']
    except BaseException:
        category = wit.use_backup_keywords(resp)

    print("Yelp Location: " + location)
    print("Yelp Category: " + category)
    result = (category, location)
    # Handling an early edge case in which AI confuses language names with
    # Yelp Ethnic foods, i.e., Chinese (language) vs Chinese (cuisine)

    msg_gen.store_reply_in_mongo(yelp_request(result), sender_info, "🍴 Yelp 🍴")

    return result
示例#2
0
def trigger_news(resp, sender_info):
    print("News Triggered")
    # print(resp)
    try:
        newsSource = resp['entities']['wit_news_source'][0]['value']
    except BaseException:
        newsSource = 'cnn'
    print("Wit.AI extracted news source: " + newsSource)

    header = "🌏 " + str(newsSource).upper() + " 🌏"
    print(header)
    msg_gen.store_reply_in_mongo(news_request(newsSource), sender_info, header)
示例#3
0
def trigger_wiki(resp, sender_info):
    print("Wikipedia Triggered")
    # print(resp)
    # print(sender_info)
    wikiSearch = resp['_text']
    try:
        wikiSearch = resp['entities']['wikipedia_search_query'][0]['value']
    except BaseException:
        wikiSearch = msg_gen.extract_quoted_text(resp['_text'])

    print("Wit.AI Wikisearch term: " + wikiSearch)
    msg_gen.store_reply_in_mongo(wikipedia_request(wikiSearch), sender_info,
                                 "🔎 Wikipedia 🔎")
示例#4
0
def trigger_news_directory(sender_info):
    news_directory_text = "Here are the available news sources you can use: \n\n📰 ABC 📰" \
                          "A.P. 📰 ABC 📰 ABC (au) 📰 Al Jazeera 📰 Ars Technica 📰 Axios 📰" \
                          " BBC 📰 BBC Sport 📰 Bleacher Report 📰 Bloomberg 📰 Business " \
                          "Insider 📰 Business Insider (uk) 📰 Buzzfeed 📰 CBC 📰 CBS 📰 " \
                          "CNBC 📰 CNN 📰 Crypto 📰 Daily Mail 📰 Engadget 📰 Entertainment Weekly 📰 ESPN 📰" \
                          " Financial Post 📰 Financial Times 📰 Fortune 📰 Fox Sports 📰 Google 📰 Google " \
                          "UK 📰 Hacker News 📰 IGN 📰\n📰 Independent 📰 Mashable 📰 Medical 📰 Metro 📰 " \
                          "Mirror 📰 MSNBC 📰 MTV 📰 MTV (uk) 📰 National Geographic 📰 National " \
                          "Review 📰 NBC 📰 New Scientist 📰 com au 📰 The Week 📰 NY Mag 📰 Futurism 📰" \
                          " NFL 📰 NHL 📰 Politico 📰 Polygon 📰 Recode 📰 Reddit 📰 Reuters 📰 " \
                          "Techcrunch 📰 Techradar 📰 The Economist 📰 Globe and Mail 📰 The Guardian 📰 " \
                          "The Guardian (au) 📰 Huffpost 📰 The Irish Times 📰 Lad Bible 📰 NY Times 📰 The Next " \
                          "Web 📰 Sport Bible 📰 The Telegraph 📰 verge 📰 Wall Street Journal 📰 Washington Post 📰 " \
                          "Washington Times 📰 Time 📰 USA Today 📰 Vice 📰 Wired 📰"
    header = "🌏 News Directory 🌏"
    print(header)
    msg_gen.store_reply_in_mongo(news_directory_text, sender_info, header,
                                 "ALL_CHUNKS")
示例#5
0
def trigger_forecast(resp, sender_info):
    sender_info = mongo.message_records.find_one(
        {"sms_id": sender_info['sms_id']})
    time.sleep(1)
    print("Forecast Triggered")
    try:
        location = resp['entities']['location'][0]['value']
    except BaseException:
        location = 'home'

    try:
        result = location
        print("Forecast location: " + location)

        msg_gen.store_reply_in_mongo(forecast_request(result, sender_info),
                                     sender_info, "🌞 Forecast 🌞", "ALL_CHUNKS")

    except BaseException:
        print("Location not found, so checking for Non-Weather keywords ...")
        wit.check_keywords(resp, sender_info)
示例#6
0
def trigger_hn(resp, sender_info):
    print("Hacker News Triggered")
    # print(resp)
    msg_gen.store_reply_in_mongo(hacker_news_request(), sender_info,
                                 "💻 Hacker News 💻")
示例#7
0
def trigger_nyt(resp, sender_info):
    print("NY Times Triggered")
    # print(resp)
    msg_gen.store_reply_in_mongo(nyt_request(), sender_info, "📰 NY Times 📰")
示例#8
0
def trigger_wolfram(resp, sender_info):
    print("Wolfram Triggered")
    # print(resp)
    msg_gen.store_reply_in_mongo(wolfram_request(resp['_text']), sender_info,
                                 "🔭 Q & A 🔭")
示例#9
0
def trigger_jeopardy(resp, sender_info):
    print("Jeopardy Triggered")
    jeopardyTuple = jeopardy_request()
    jeopardyTogether = jeopardyTuple[0] + jeopardyTuple[1]
    msg_gen.store_reply_in_mongo(jeopardyTogether, sender_info, "📺 Jeopardy 📺",
                                 "ALL_CHUNKS")
示例#10
0
def trigger_directions(resp, sender_info):
    sender_info = mongo.message_records.find_one({"sms_id": sender_info['sms_id']})
    time.sleep(1)
    print("Directions Triggered")
    # print(resp)
    start_location = ""
    end_location = ""

    try:
        transit_method = resp['entities']['wit_transit'][0]['value']
    except BaseException:
        transit_method = "drive"

    home_status = ""

    try:
        home_status = resp['entities']['wit_fromHome'][0]['value']
        print(home_status)
    except BaseException:
        home_status = ""

    if (home_status != ""):
        if (home_status == "from home"):
            start_location = "home"
            try:
                end_location = resp['entities']['location'][0]['value']
            except BaseException:
                pass
        else:
            try:
                start_location = resp['entities']['location'][0]['value']
            except BaseException:
                pass
            end_location = "home"
    else:
        try:
            start_location = resp['entities']['location'][0]['value']
        except BaseException:
            pass
        try:
            end_location = resp['entities']['location'][1]['value']
        except BaseException:
            pass

    backupAddresses = fallback_multi_address_parse(resp['_text'])
    if (start_location == "" and end_location == ""):
        start_location = backupAddresses[0]
        end_location = backupAddresses[1]
    elif (end_location == ""):
        end_location = backupAddresses[1]
    elif (start_location == ""):
        start_location = backupAddresses[1]

    directions_data = [start_location, end_location, transit_method]
    print(
        "Origin: " +
        start_location +
        "\nDestination: " +
        end_location +
        "\nTransit: " +
        transit_method)


    msg_gen.store_reply_in_mongo(
                                       directions_request(
                                           directions_data,
                                           sender_info),
                                       sender_info,
                                       "🚗 Directions 🚗",
                                       "ALL_CHUNKS")