Example #1
0
def say_hello(name):
    ''' Ask the use to say hello. '''
    greetings = [
        "hi",
        "hello",
        "morning",
        "afternoon",
        "evening",
    ]
    welcome = ("Hi there, {}!".format(name) 
             + " Lets start with something easy. Say hello!")
    continuing = True
    i = 0
    while continuing:
        recieved = paul.interact(welcome, response="arb")
        if paul.has_one_of(paul.Sentence(recieved), greetings):
            continuing = False
            paul.interact("Fantastic! Moving on...")
        elif i > 3:
            continuing = False
            paul.interact("Never mind! Moving on...")
        else:
            i += 1
            welcome = "Hmmm, I couldn't understand that,"
            welcome += " lets give it another shot."
    ask_weather()
Example #2
0
def process(sentence):
    ''' Process the sentence '''
    r = paul.PAUL_ROOT
    modules = [file[:-3] for file in os.listdir(r + "/Modules/") 
              if file[-3:] == ".py" 
              and file not in [
                  "__init__.py", 
                  "importer.py",
                  "personality.py",
                  "loader.py"]
              ]
    paul.log("MDLS:", modules)
    wrd = extract_word(sentence, modules, two_helps=True)
    if wrd:
        return get_help(wrd)
    helping = "I'm more than happy to help! "
    helping += "I'm able to help with:\n"
    for m in modules:
        helping += "  " + m[0].upper() + m[1:] + "\n"
    paul.interact(helping[:-1])
    r = paul.interact("Which do you want to know about?", response="arb")
    s = paul.Sentence(r)
    if s.has_one_of(["none", "never", "no", "nope", "exit", "stop"]):
        paul.acknowledge()
        return
    wrd = extract_word(s, modules, two_helps=False)
    if wrd:
        return get_help(wrd)
    else:
        return "I wasn't quite sure what you needed help with..."
Example #3
0
 def read_message(self, num):
     ''' Read the message num '''
     typ, data = self.incoming.fetch(num, '(RFC822)')
     message = email.message_from_string(str(data[0][1], encoding='utf8'))
     messages = message.walk()
     options = {"plain": None, "html": None}
     for m in messages:
         if m.get_content_type() == "text/plain":
             options["plain"] = m.get_payload()
         elif m.get_content_type() == "text/html":
             options["html"] = m.get_payload()
     paul.interact(options["plain"] if options["plain"] else "I can't really understand this email, you'll have to read it yourself later. Sorry.")
Example #4
0
def list_abilities(fin):
    ''' Let the user know what Paul is capable of. '''
    final_speech = ("Well, I think that gives the basic idea nicely.\n"
                  + "However, my abilities are far greater than "
                  + "telling you the weather. I can also:\n"
                  + "  • Tell the time and date\n"
                  + "  • Control volume and brightness on your computer\n"
                  + "  • Locate and open files\n"
                  + "  • Calculate solutions to equations, including "
                  + "basic Algebra\n"
                  + "  • Play you songs from your iTunes library\n"
                  + "  • Change my own settings\n"
                  + "  • Research a subject using wikipedia\n"
                  + "  • And if all else fails, I can google that for you.\n"
                  + "I think you get the idea. Let's begin.")
    paul.interact(fin + "\n" + final_speech)
Example #5
0
def choose(list_choices):
    ''' Choose the item from what we found '''
    
    question = "Which of these do you want? \n"
    options = "\n".join([str(index + 1) + ". " +
                         "/".join(item.split("/")[3:]) for 
                         index, item in enumerate(list_choices)])
    choice = paul.interact(question + options, "list")
    if choice is not None and choice <= 5 and choice > 0:
        paul.log("CHOICE: " + str(choice))
        return list_choices[choice - 1]
    return None
Example #6
0
def ask_weather():
    ''' Ask the user to get the weather '''
    import Modules.weather as weather
    reply = paul.interact("To get the ball rolling, ask me a question. "
                        + "Let's try\n"
                        + '    "How is the weather?"', response="arb")
    ending = False
    i = 0
    fin = ""
    while not ending:
        sentence = paul.Sentence(reply)
        print(sentence, weather.NOUNS, sentence.has_one_of(weather.NOUNS))
        if i > 3:
            fin = "Doesn't matter. Onward!"
            ending = True
        elif sentence.has_one_of(weather.NOUNS):
            ending = True
            fin = weather.process(sentence)
        else:
            reply = paul.interact("Hmm, that doesn't really sound like a " 
                    + "question about the weather. Give it another shot.",
                    response="arb")
        i += 1
    list_abilities(fin)
Example #7
0
 def get_unread(self):
     self.incoming.select()
     typ, data = self.incoming.search(None, 'UnSeen')
     if str(data[0], encoding='utf8') == "":
         return ("You have no new messages.")
     else:
         num = str(data[0], encoding='utf8').split()
         r = paul.interact(
                           "You have {} unread message{}. ".format(
                                   len(num), 
                                   "s" if len(num) != 1 else ""
                           )
                           + "Do you want me to read {}?".format(
                               "them" if len(num) != 1 else "it"
                           ),
                           response="y_n")
         if r:
             for n in num:
                 self.read_message(n)
         else:
             return "Ok."