示例#1
0
 def __init__(self,
              label="",
              street="",
              city="",
              stateCode="",
              countryCode="",
              postalCode="",
              latitude=0,
              longitude=0,
              detailType="BUSINESS_ITEM",
              clazz="MapItem"):
     super(MapItem, self).__init__("com.apple.ace.localsearch",
                                   clazz="MapItem")
     self.label = label
     self.detailType = detailType
     self.location = Location(label, street, city, stateCode, countryCode,
                              postalCode, latitude, longitude)
     self.placeId = None
     self.distanceInMiles = None
     self.detail = None  #AceObject
示例#2
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
示例#3
0
 def createNewReminder(self, content, correctTime, timetype, EndDate):
     tz = timezone(self.connection.assistant.timeZoneId)
     ##print EndDate
     ##print correctTime
     if timetype == "Relative":
         trig = ReminderDateTimeTrigger()
         trig.timeZoneId = self.connection.assistant.timeZoneId
         trig.date = EndDate
         x = ReminderObject()
         x.trigger = trig
         x.important = False
         x.completed = False
         x.subject = content.capitalize().strip("in")
         x.dueDate = EndDate
         x.dueDateTimeZoneId = trig.timeZoneId
         
     if timetype == "Hour":
         trig = ReminderDateTimeTrigger()
         trig.timeZoneId = self.connection.assistant.timeZoneId
         trig.date = correctTime
         x = ReminderObject()
         x.important = False
         x.completed = False
         x.subject = content.capitalize().strip("at")
         x.trigger = trig
         x.dueDate = correctTime
         x.dueDateTimeZoneId = trig.timeZoneId
         
     if timetype[0] == "Location":
         if timetype[1] == "Arrival":
             ArriveDepart = "OnArrival"
         if timetype[1] == "Departure":
             ArriveDepart = "OnDeparture"
         x = None
         
         if correctTime == "Here":
             x = self.herefind()
             identifier = None
         else:
             x = self.locationFind(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"
             trig = ReminderLocationTrigger()
             trig.contactIdentifier = identifier
             trig.timing = ArriveDepart
             trig.location = Loc
             x = ReminderObject()
             x.important = False
             x.completed = False
             x.subject = content.capitalize().strip("at")
             x.trigger = trig        
         else:
             self.say("Sorry, I couldn't find that location in your contact card")
             self.complete_request()
         
     answer = self.getResponseForRequest(DomainObjectCreate(self.refId, x))
     if ObjectIsCommand(answer, DomainObjectCreateCompleted):
         answer = DomainObjectCreateCompleted(answer)
         x = ReminderObject()
         x.identifier = answer.identifier
         return x
     else:
         return None