Пример #1
0
 def __init__(self):
     self.speaker = AssistantSpeaker()
     self.listener = AssistantListener()
     self.dateFormat = Constants.MEETING_DATE_FORMAT
     self.appJsonFile = JsonFileUtil(Constants.APP_PROPERTIES_FILENAME,
                                     Constants.APP_PROPERTIES_PATH)
     self.meetingJsonFile = JsonFileUtil(Constants.MEETING_FILENAME,
                                         Constants.MEETING_FILEPATH)
     self.intervalMeetingReminderKey = Constants.APP_PROP_INTERVALMEETING_PARAM
Пример #2
0
class TimeCommand:
    def __init__(self):
        self.speaker = AssistantSpeaker()
        self.listener = AssistantListener()

    def executeCommand(self):
        self.speaker.say("For which city do you want the current time ?")
        city = self.listener.listen()
        if city == -1:
            self.speaker.say(
                "Sorry I did not understand the name of the city.")
            return -1
        print(city)
        self.speaker.say(
            "Please wait while I'm looking for the current time in " + city)
        print("Prepare Selenium webdriver to get the time")

        string_current_time_city = self.getTimeFromWebSite(city)

        self.speaker.say("In " + city + " it is " + string_current_time_city +
                         " o'clock.")

    def getTimeFromWebSite(self, city):

        options = webdriver.ChromeOptions()
        options.add_argument(Constants.DRIVER_ARGUMENT)
        driver = webdriver.Chrome(executable_path=Constants.DRIVER_EXEC_PATH,
                                  chrome_options=options)
        driver.get(Constants.TIME_URL + city)

        # Use beautifulSoup to parse the source page for better performance
        soup = BeautifulSoup(driver.page_source,
                             Constants.BEAUTIFUL_SOUP_PARSER)
        answer = soup.find('td', id='p0')

        print('Quit driver')
        # Important to close the driver to avoid having multiple chrome tasks
        # opened at the same time
        driver.quit()

        # Date is with format 'Day Hour:Minute AM'
        splited_answer = answer.text.split()
        return splited_answer[1] + ' ' + splited_answer[2]
Пример #3
0
class StartActionThread(QThread):
    signal = pyqtSignal('PyQt_PyObject')

    def __init__(self, command=None):
        QThread.__init__(self)
        self.speaker = AssistantSpeaker()
        self.listener = AssistantListener()
        self.commandHandler = CommandHandler()
        self.command = command

    def run(self):

        if self.command is None:
            self.speaker.say("Tell me your command")
            self.command = self.listener.listen()

        # -1 means a WaitTimeoutException occured
        if (self.command == -1):
            self.speaker.say("Sorry, I could not understand the command")
        else:
            self.commandHandler.executeCommand(self.command)

        self.signal.emit("finished")
Пример #4
0
class HelpCommand:
    
    def __init__(self):
        self.speaker = AssistantSpeaker()
        self.listener = AssistantListener()
            
    def executeCommand(self):
        self.speaker.say("For which command do you need help ?")
        command_for_help = self.listener.listen()

        if command_for_help == 'weather':
            self.speaker.say("Simply say weather and you will have the current temperature in Montreal.")
        elif command_for_help == 'change parameters':
            self.speaker.say("After saying the command name, you will be ask to say the parameter name and the parameter value.")
        elif command_for_help == 'time':
            self.speaker.say("After saying the command name, you will be ask to say the name of the city. You will then hear the current time of the most likely city found.")
        elif command_for_help == 'all commands':
            self.speaker.say("Give all the available commands in the application.")
        elif command_for_help == 'remind meetings':
            self.speaker.say("The assistant will say all the upcoming meetings the the user. All the meetings from today plus the days interval specified in the interval meeting reminder application parameter will be reminded.")
        elif command_for_help == 'save meeting':
            self.speaker.say("For saving a meeting, you need too give, when it is asked, the year, the month (using number from 1 to 12), the day (using number from 1 to 31), the hour (using number from 0 to 24), the minute (using number from 0 to 60) and the meeting content")
        else:
            self.speaker.say("Sorry this command doesn't exist. For a list of all available commands, say All commands.")
Пример #5
0
 def __init__(self, command=None):
     QThread.__init__(self)
     self.speaker = AssistantSpeaker()
     self.listener = AssistantListener()
     self.commandHandler = CommandHandler()
     self.command = command
Пример #6
0
 def __init__(self):
     self.speaker = AssistantSpeaker()
     self.listener = AssistantListener()
 def __init__(self):
     self.speaker = AssistantSpeaker()
     self.listener = AssistantListener()
     self.dateFormat = Constants.MEETING_DATE_FORMAT
     self.meetingJsonFile = JsonFileUtil(Constants.MEETING_FILENAME, Constants.MEETING_FILEPATH)
class MeetingCommand:
    
    def __init__(self):
        self.speaker = AssistantSpeaker()
        self.listener = AssistantListener()
        self.dateFormat = Constants.MEETING_DATE_FORMAT
        self.meetingJsonFile = JsonFileUtil(Constants.MEETING_FILENAME, Constants.MEETING_FILEPATH)
    
    
    def getMeetingDateFromUser(self):
        
        dateIsValid = False
        while(dateIsValid is not True):
            year = self.getDateElement("year");
            month = self.getDateElement("month");
            day = self.getDateElement("day");
            hour = self.getDateElement("hour");
            minute = self.getDateElement("minute");
            
            try:
                dateOfMeeting = datetime.datetime(year, month, day, hour, minute)
                dateIsValid = True
            except ValueError:
                self.speaker.say("The given date was invalid, please record it again")
                dateIsValid = False
            
        print(dateOfMeeting)
        return dateOfMeeting
    
    def getDateElement(self, elementOfDate):
        dateElement = -1
        # listener.listen return -1 if there is a Waittimeout error
        while(dateElement == -1):
            self.speaker.say("What is the number of the " + elementOfDate + " for the meeting ?")
            dateElement = self.listener.listen()
            try:
                dateElement = int(dateElement)
            except ValueError:
                self.speaker.say("The given " + elementOfDate + " is not valid.")
                dateElement = -1
        print("Element of date is " + str(dateElement))
        return dateElement
    
    
    def getMeetingSubjectFromUser(self):
        # listener.listen return -1 if there is a Waittimeout error
        subjectOfMeeting = -1
        while(subjectOfMeeting == -1):
            self.speaker.say("Please say what you want to remember at this date")
            subjectOfMeeting = self.listener.listen()
            print(subjectOfMeeting)
        return subjectOfMeeting
    
    
    def saveNewMeeting(self, dateOfMeeting, subjectOfMeeting):
        currentJsonData = self.meetingJsonFile.getData()
        dateOfMeetingInString = dateOfMeeting.strftime(self.dateFormat)

        if dateOfMeetingInString not in currentJsonData:
            currentJsonData[dateOfMeetingInString] = subjectOfMeeting
        else:
            currentMeetingsForDate = currentJsonData[dateOfMeetingInString]
            currentJsonData[dateOfMeetingInString] = currentMeetingsForDate + " and you also have " + subjectOfMeeting
        
        with open(Constants.MEETING_FILENAME, 'w+') as file:
            json.dump(currentJsonData, file, ensure_ascii=False)
                
        self.speaker.say("Meeting successfully saved")
        
        
    def executeCommand(self):
        
        self.speaker.say("Let's save a meeting!")
        
        dateOfMeeting = self.getMeetingDateFromUser()

        subjectOfMeeting = self.getMeetingSubjectFromUser()
        
        self.saveNewMeeting(dateOfMeeting, subjectOfMeeting)