Example #1
0
def process(sentence):
    """ Process the sentence, and go to Google """

    if is_math(sentence):
        return sentence.forward("math")

    sentence.replace_it()

    engines = {
        "google": "http://www.google.com/search?q={}",
        "bing": "http://www.bing.com/search?q={}",
        "yahoo": "http://search.yahoo.com/search?p={}",
        "duckduckgo": "https://duckduckgo.com/?q={}",
        "baidu": "http://www.baidu.com/s?wd={}",
    }
    engine = paul.get_search_engine().lower()

    keywords = sentence.keywords(ignore=[engine])
    paul.log("KEYWORDS:", keywords)

    query = "+".join([word.replace(" ", "+") for word, _ in keywords if word not in VERBS + NOUNS])
    url = engines[engine].format(query)

    paul.log("URL: " + url)
    paul.loading()
    paul.open_URL(url)
    return "Here, try this."
Example #2
0
def process(sentence):
    ''' Process the sentence, act as necessary '''
    
    paul.loading()
    ignore = [
        "weather",
        "forecast",
        "rainy",
        "rain",
        "raining",
        "sunny",
        "temperature",
        "cold",
        "hot",
        "humid",
    ]
    
    keywords = sentence.keywords()
    paul.log("KEYWORDS: " + str(keywords))
    
    today = datetime.date.today().weekday()
    paul.log("TODAY: " + str(today))
    
    day_index = 0
    
    weekdays = ['monday', 'tuesday', 'wednesday', 
                'thursday', 'friday', 'saturday', 'sunday']
    
    if (len(keywords) == 0 
        or paul.has_one_of(keywords, ['today', 'now', "today's"])):
        day_index = 0
    elif paul.has_one_of(keywords, ['tomorrow', "tomorrow's"]):
        day_index = 2
    elif paul.has_one_of(keywords, weekdays):
        for day in weekdays:
            if paul.has_word(keywords, day):
                paul.log("DAY:", day)
                day_index = (weekdays.index(day) + today) % 7 + 1
            if day_index == 1:
                day_index = 0
    
    paul.log("DAY: " + str(day_index))
    
    return weather(day_index, sentence)
Example #3
0
def process(sentence):
    ''' Process the sentence '''
    
    sentence.replace_it()
    
    keywords = sentence.keywords()
    paul.log("KEYWORDS: " + str(keywords))
    
    ignores = ["i", "wikipedia"]
    filtered_keywords = [word for word in keywords if word[0] not in ignores]
    
    paul.loading()
    if filtered_keywords == []:
        return "I don't understand. Sorry!"
    if filtered_keywords[0][0] in ["joke", "jokes"]:
        if sentence.has_word("about"):
            pass
        else:
            return sentence.forward("personality")
    elif filtered_keywords[0][0].startswith("http"):
        paul.open_URL(filtered_keywords[0][0])
    return findIt(filtered_keywords[0][0], sentence)