Пример #1
0
    def changeName(self, nameType, value):      
      meSearch = ABPersonSearch(self.refId)
      meSearch.me = True
      meSearch.scope = "Local"
      
      answer = self.getResponseForRequest(meSearch)
      
      if ObjectIsCommand(answer, ABPersonSearchCompleted):
	results = ABPersonSearchCompleted(answer)
	results = results.results[0]
      else:
	raise StopPluginExecution("Unknown response: {0}".format(answer))
      
      mePerson = ABPerson()
      mePerson.identifier = results.identifier
      
      domainRetrieve = DomainObjectRetrieve(self.refId)
      domainRetrieve.identifiers = [mePerson]
      
      domainAnswer = self.getResponseForRequest(domainRetrieve)
      
      if not ObjectIsCommand(domainAnswer, DomainObjectRetrieveCompleted):
	raise StopPluginExecution("Unknown response: {0}".format(domainAnswer))      

      domainUpdate = DomainObjectUpdate(self.refId)
      domainUpdate.identifier = mePerson
      
      newName = ABPerson()
      
      if nameType in ["nick", "nick name"]:
	newName.nickName = value
      if nameType in ["firstName", "first name"]:
	newName.firstName = value
      if nameType in ["lastName", "last name"]:
	newName.lastName = value
      
      domainUpdate.setFields = newName
      
      updateAnswer = self.getResponseForRequest(domainUpdate)
      
      if not ObjectIsCommand(updateAnswer, DomainObjectUpdateCompleted):
	raise StopPluginExecution("Unknown response: {0}".format(updateAnswer))
      
      domainCommit = DomainObjectCommit(self.refId)
      domainCommit.identifier = mePerson
      
      commitAnswer = self.getResponseForRequest(domainCommit)
      
      if not ObjectIsCommand(commitAnswer, DomainObjectCommitCompleted):
	raise StopPluginExecution("Unknown response: {0}".format(commitAnswer))
Пример #2
0
	def askAndSetMessage(self, sms, language):
		createAnchor = self.createSmsSnippet(sms, False, "CreateSms#smsMissingMessage", random.choice(responses['askForMessage'][language]), language)
		time = self.getResponseForRequest(createAnchor)
		tz = timezone(self.connection.assistant.timeZoneId)
		Date = datetime.now(tz)
		EndDate = None
		if "in" in time.lower():
			m = re.match(res['setTimer'][language], time, re.IGNORECASE)
			if m == None:
				self.say("Sorry, that\'s not a valid time.")
				self.complete_request()
				return
			timer_length = m.group('length')
			offsetlength = parse_timer_length(timer_length, language)
			offset = ReminderDateTimeTriggerOffset()
			offset.offsetValue = offsetlength
			offset.offsetTimeUnit = "Second"
			EndDate = Date + timedelta(seconds=offsetlength)
			trig = ReminderDateTimeTrigger()
			trig.timeZoneId = self.connection.assistant.timeZoneId
			trig.relativeTimeOffset = offset
		if "at" in time.lower():
			hourtoset = parse_time(self, time, language)
			EndDate = hourtoset
			trig = ReminderDateTimeTrigger()
			trig.timeZoneId = self.connection.assistant.timeZoneId
			trig.date = hourtoset
		if EndDate == None:
			self.say("Sorry, I didn\'t understand that")
			self.complete_request()
			return			
		# update the domain object		 
	 
		updateCMD = DomainObjectUpdate(self.refId)
		updateCMD.identifier = sms		  
		updateCMD.setFields = ReminderObject()
		updateCMD.setFields.trigger = trig
		updateCMD.setFields.important = False
		updateCMD.setFields.dueDate = EndDate
		updateCMD.setFields.completed = False
		updateCMD.setFields.dueDateTimeZoneId = trig.timeZoneId
		
		
		answer = self.getResponseForRequest(updateCMD)
		if ObjectIsCommand(answer, DomainObjectUpdateCompleted):
			return sms
		else:
			return None
Пример #3
0
    def askAndSetMessage(self, sms, language):
        createAnchor = self.createSmsSnippet(sms, False, "CreateSms#smsMissingMessage", random.choice(responses['askForMessage'][language]), language)

        smsText = self.getResponseForRequest(createAnchor)
        # update the domain object
        
        updateCMD = DomainObjectUpdate(self.refId)
        updateCMD.identifier = sms
        updateCMD.addFields = SmsSms()
        updateCMD.setFields = SmsSms()
        updateCMD.setFields.message = smsText
        updateCMD.removeFields = SmsSms()
        
        answer = self.getResponseForRequest(updateCMD)
        if ObjectIsCommand(answer, DomainObjectUpdateCompleted):
            return sms
        else:
            return None
Пример #4
0
    def askAndSetMessage(self, sms, language):
        createAnchor = self.createSmsSnippet(
            sms, False, "CreateSms#smsMissingMessage",
            random.choice(responses['askForMessage'][language]), language)

        smsText = self.getResponseForRequest(createAnchor)
        # update the domain object

        updateCMD = DomainObjectUpdate(self.refId)
        updateCMD.identifier = sms
        updateCMD.addFields = SmsSms()
        updateCMD.setFields = SmsSms()
        updateCMD.setFields.message = smsText
        updateCMD.removeFields = SmsSms()

        answer = self.getResponseForRequest(updateCMD)
        if ObjectIsCommand(answer, DomainObjectUpdateCompleted):
            return sms
        else:
            return None
Пример #5
0
    def askAndSetTime(self, reminder, language):
        tz = timezone(self.connection.assistant.timeZoneId)
        x = datetime.now(tz)
        pmWords = ["pm", "tonight"]
        amWords = ["am"]
        correctTime = None
        State = "noTime"
        Satisfied = False
        while not Satisfied:
            createAnchor = self.createReminderSnippet(reminder, False, "Createreminder#reminderMissingTime", random.choice(responses['queryReminderTime'][language]), language)
            answer = self.getResponseForRequest(createAnchor)
            relativematch = re.match('in ((?P<relative>(?P<relativeinteger>([0-9/ ])*|in||a|an|the)\s+(?P<relativeunits>(minutes?|hrs?|hours?|days?|weeks?))))', answer, re.IGNORECASE)
            if relativematch is not None:
                State = "Time"
                Satisfied = True
                print "relativefound"
                timetype = "Relative"
                relativeint = relativematch.group('relativeinteger')
                relativeunit = relativematch.group('relativeunits').strip("s").title()
                if relativeunit == "Minute":
                    z = int(relativeint) * 60
                    correctTime = x + timedelta(seconds=z)
                if relativeunit == "Hour":
                    z = int(relativeint) * 60 * 60
                    correctTime = x + timedelta(seconds=z)
                if relativeunit == "Day":
                    z = int(relativeint) * 24 * 60 * 60
                    correctTime = x + timedelta(seconds=z)
                if relativeunit == "Week":
                    z = int(relativeint) * 7 * 24 * 60 * 60
                    correctTime = x + timedelta(seconds=z)
                
            weekdaymatch = re.match('(?P<weekday>on (?P<dayofweek>(monday?|tuesday?|wednesday?|thursday?|friday?|saturday?|sunday?)) at ((?P<weekdayhour>([0-9]{1,4}):?\s*([0-9]{2})?\s*)(?P<weekdayampm>(am|pm))?|noon|midnight)(\s|$))', answer, re.IGNORECASE)
            if weekdaymatch is not None:
                State = "Time"
                Satisfied = True
                timetype = "Hour"
                dayofweek = weekdaymatch.group('dayofweek')
                parsehour = weekdaymatch.group('weekdayhour')
                hour = weekdaymatch.group('weekdayhour')
                timehint = weekdaymatch.group('weekdayampm')
                if dayofweek == "monday":
                    dayofweek = 1
                if dayofweek == "tuesday":
                    dayofweek = 2
                if dayofweek == "wednesday":
                    dayofweek = 3
                if dayofweek == "thursday":
                    dayofweek = 4
                if dayofweek == "friday":
                    dayofweek = 5
                if dayofweek == "saturday":
                    dayofweek = 6
                if dayofweek == "sunday":
                    dayofweek = 7
                if timehint == "":
                    if int(hour) > 1259:
                        sethour = parsehour[0:2]
                        minutes = parsehour[2:4]
                        correctTime = x.replace(hour=int(sethour), minute=int(minutes), second=0, microsecond=0)
                    else:
                        if 2 < len(hour) < 4:
                            sethour = parsehour[0:1]
                            minutes = parsehour[1:3]
                            correctTime = x.replace(hour=int(sethour), minute=int(minutes), second=0, microsecond=0)
                        if len(hour) > 3:
                            sethour = parsehour[0:2]
                            minutes = parsehour[2:4]
                            correctTime = x.replace(hour=int(sethour), minute=int(minutes), second=0, microsecond=0)
                        if len(hour) == 1:
                            sethour = parsehour[0:1]
                            correctTime = x.replace(hour=int(sethour), minute=0, second=0, microsecond=0)
                        if len(hour) == 2:
                            print "yay"
                            sethour = parsehour[0:2]
                            correctTime = x.replace(hour=int(sethour), minute=0, second=0, microsecond=0)
                if len(str(hour)) < 4:
                    for pmhints in pmWords:
                        if pmhints in timehint:
                            if int(hour) == 12:
                                correctTime = x.replace(hour=int(hour), minute=0, second=0, microsecond=0)
                            if int(hour) != 12:
                                hour = int(hour) + 12
                                correctTime = x.replace(hour=hour, minute=0, second=0, microsecond=0)
                    for amhints in amWords:
                        if amhints in timehint:
                            if int(hour) == 12:
                                correctTime = x.replace(hour=23, minute=59, second=0, microsecond=0)
                            if int(hour) != 12:
                                correctTime = x.replace(hour=int(hour), minute=0, second=0, microsecond=0)
                if len(str(hour)) > 3:
                    if len(str(hour)) == 4:
                        hour = parsehour[0]
                        minutes = parsehour[1:3]
                    if len(str(hour)) == 5:
                        hour = parsehour[0:2]
                        minutes = parsehour[2:4]
                    x = datetime.now(tz)
                    for pmhints in pmWords:
                        if pmhints in timehint:
                            if int(hour) == 12:
                                correctTime = x.replace(hour=int(hour), minute=int(minutes), second=0, microsecond=0)
                            if int(hour) != 12:
                                hour = int(hour) + 12
                                correctTime = x.replace(hour=int(hour), minute=int(minutes), second=0, microsecond=0)
                    for amhints in amWords:
                        if amhints in timehint:
                            if int(hour) == 12:
                                correctTime = x.replace(hour=23, minute=59, second=0, microsecond=0)
                            if int(hour) != 12:
                                correctTime = x.replace(hour=int(hour), minute=int(minutes), second=0, microsecond=0)
                if x.isoweekday() < dayofweek:
                    difference = dayofweek - x.isoweekday()
                    correctTime = correctTime + timedelta(days=difference)
                if x.isoweekday() > dayofweek:
                    difference = dayofweek - x.isoweekday() + 7
                    correctTime = correctTime + timedelta(days=difference)

            hourmatch = re.match('(?P<signal>(at|by)) (?P<hour>([0-9]{1,4}):?\s*([0-9]{2})?\s*)(?P<ampm>(am|pm|tonight|in the morning)?|noon|midnight)(\s|$)', answer, re.IGNORECASE)       
            if hourmatch is not None:
                    State = "Time"
                    Satisfied = True
                    timetype = "Hour"
                    parsehour = hourmatch.group('hour')
                    hour = hourmatch.group('hour')
                    timehint = hourmatch.group('ampm')
                    if timehint == "":
                        if int(hour) > 1259:
                            sethour = parsehour[0:2]
                            minutes = parsehour[2:4]
                            correctTime = x.replace(hour=int(sethour), minute=int(minutes), second=0, microsecond=0)
                        else:
                            if 2 < len(hour) < 4:
                                sethour = parsehour[0:1]
                                minutes = parsehour[1:3]
                                correctTime = x.replace(hour=int(sethour), minute=int(minutes), second=0, microsecond=0)
                            if len(hour) > 3:
                                sethour = parsehour[0:2]
                                minutes = parsehour[2:4]
                                correctTime = x.replace(hour=int(sethour), minute=int(minutes), second=0, microsecond=0)
                            if len(hour) == 1:
                                sethour = parsehour[0:1]
                                correctTime = x.replace(hour=int(sethour), minute=0, second=0, microsecond=0)
                            if len(hour) == 2:
                                print "yay"
                                sethour = parsehour[0:2]
                                correctTime = x.replace(hour=int(sethour), minute=0, second=0, microsecond=0)
                    if len(str(hour)) < 4:
                        for pmhints in pmWords:
                            if pmhints in timehint:
                                if int(hour) == 12:
                                    correctTime = x.replace(hour=int(hour), minute=0, second=0, microsecond=0)
                                if int(hour) != 12:
                                    hour = int(hour) + 12
                                    correctTime = x.replace(hour=hour, minute=0, second=0, microsecond=0)
                        for amhints in amWords:
                            if amhints in timehint:
                                if int(hour) == 12:
                                    correctTime = x.replace(hour=23, minute=59, second=0, microsecond=0)
                                if int(hour) != 12:
                                    correctTime = x.replace(hour=int(hour), minute=0, second=0, microsecond=0)
                    if len(str(hour)) > 3:
                        if len(str(hour)) == 4:
                            hour = parsehour[0]
                            minutes = parsehour[1:3]
                        if len(str(hour)) == 5:
                            hour = parsehour[0:2]
                            minutes = parsehour[2:4]
                        x = datetime.now(tz)
                        for pmhints in pmWords:
                            if pmhints in timehint:
                                if int(hour) == 12:
                                    correctTime = x.replace(hour=int(hour), minute=int(minutes), second=0, microsecond=0)
                                if int(hour) != 12:
                                    hour = int(hour) + 12
                                    correctTime = x.replace(hour=int(hour), minute=int(minutes), second=0, microsecond=0)
                        for amhints in amWords:
                            if amhints in timehint:
                                if int(hour) == 12:
                                    correctTime = x.replace(hour=23, minute=59, second=0, microsecond=0)
                                if int(hour) != 12:
                                    correctTime = x.replace(hour=int(hour), minute=int(minutes), second=0, microsecond=0)
                    if hourmatch.group('signal') == "by":
                        correctTime = correctTime - timedelta(minutes=30)
                    if correctTime < x:
                        correctTime = correctTime + timedelta(days=1)

            locationmatch = re.match('(?P<location>When I ((?P<arrive>(get|arrive))|(?P<leave>(leave)))( to)?( at)? ((?P<default>home|work)|(?P<custom>[\S]+$)))', answer, re.IGNORECASE)
            if locationmatch is not None:
                State = "Time"
                Satisfied = True
                if locationmatch.group('arrive'):
                    timetype = ["Location", "Arrival"]
                if locationmatch.group('leave'):
                    timetype = ["Location", "Departure"]
                if locationmatch.group('default'):
                    locationToSearch = locationmatch.group('default')
                    locationToSearch = locationToSearch.capitalize()
                    correctTime = "_$!<{0}>!$_".format(locationToSearch)
                if locationmatch.group('custom'):
                    locationToSearch = locationmatch.group('custom')
                    correctTime = locationToSearch.capitalize()
                if timetype[1] == "Arrival":
                    ArriveDepart = "OnArrival"
                if timetype[1] == "Departure":
                    ArriveDepart = "OnDeparture"
                x = None

                if correctTime == "Here":
                    x = self.herefind()
                    identifier = None
                else:
                    x = locationFind(self, correctTime)
                    identifier = x[7]
                if x != None:
                    print x
                    Loc = Location()
                    Loc.street = x[2]
                    Loc.countryCode = x[6]
                    Loc.city = x[3]
                    Loc.label = correctTime
                    Loc.postalCode = x[4]
                    Loc.latitude = x[0]
                    Loc.stateCode = x[5]
                    Loc.longitude = x[1]
                    Loc.accuracy = "10.0"
                if x == None:
                    self.say("Sorry, I couldn't find that location in your contact card")
                    self.complete_request()
        
        if State == "noTime":
            self.say("Sorry, I didn't understand that...")        
        if timetype[0] == "Location":
            trig = ReminderLocationTrigger()
            trig.contactIdentifier = identifier
            trig.timing = ArriveDepart
            trig.location = Loc
        if timetype[0] is not "Location":
            trig = ReminderDateTimeTrigger()
            trig.timeZoneId = self.connection.assistant.timeZoneId
            trig.date = correctTime

        updateCMD = DomainObjectUpdate(self.refId)
        updateCMD.identifier = reminder       
        updateCMD.setFields = ReminderObject()
        updateCMD.setFields.trigger = trig
        updateCMD.setFields.important = False
        if timetype[0] is not "Location":
            updateCMD.setFields.dueDate = correctTime
            updateCMD.setFields.dueDateTimeZoneId = trig.timeZoneId
        updateCMD.setFields.completed = False

        
        
        answer = self.getResponseForRequest(updateCMD)
        if ObjectIsCommand(answer, DomainObjectUpdateCompleted):
            return reminder
        else:
            return None