コード例 #1
0
ファイル: timePlugin.py プロジェクト: waynesg511/SiriServer-1
    def currentTime(self, speech, language):
        #first tell that we look it up
        view = AddViews(self.refId, dialogPhase="Reflection")
        view.views = [
            AssistantUtteranceView(
                text=timePlugin.localizations['currentTime']['search']
                [language],
                speakableText=timePlugin.localizations['currentTime']['search']
                [language],
                dialogIdentifier="Clock#getTime")
        ]
        self.sendRequestWithoutAnswer(view)

        # tell him to show the current time
        view = AddViews(self.refId, dialogPhase="Summary")
        view1 = AssistantUtteranceView(
            text=timePlugin.localizations['currentTime']['currentTime']
            [language],
            speakableText=timePlugin.localizations['currentTime']
            ['currentTime'][language],
            dialogIdentifier="Clock#showTimeInCurrentLocation")
        clock = ClockObject()
        clock.timezoneId = self.connection.assistant.timeZoneId
        view2 = ClockSnippet(clocks=[clock])
        view.views = [view1, view2]
        self.sendRequestWithoutAnswer(view)
        self.complete_request()
コード例 #2
0
ファイル: timePlugin.py プロジェクト: 413x/SiriServer
    def currentTime(self, speech, language):
        # first tell that we look it up
        view = AddViews(self.refId, dialogPhase="Reflection")
        view.views = [
            AssistantUtteranceView(
                text=timePlugin.localizations["currentTime"]["search"][language],
                speakableText=timePlugin.localizations["currentTime"]["search"][language],
                dialogIdentifier="Clock#getTime",
            )
        ]
        self.sendRequestWithoutAnswer(view)

        # tell him to show the current time
        view = AddViews(self.refId, dialogPhase="Summary")
        view1 = AssistantUtteranceView(
            text=timePlugin.localizations["currentTime"]["currentTime"][language],
            speakableText=timePlugin.localizations["currentTime"]["currentTime"][language],
            dialogIdentifier="Clock#showTimeInCurrentLocation",
        )
        clock = ClockObject()
        clock.timezoneId = self.connection.assistant.timeZoneId
        view2 = ClockSnippet(clocks=[clock])
        view.views = [view1, view2]
        self.sendRequestWithoutAnswer(view)
        self.complete_request()
コード例 #3
0
    def currentTimeIn(self, speech, language, matchedRegex):

        self.showWait(language)

        location = matchedRegex.group("loc")
        # ask google to enhance the request
        googleGuesser = "http://maps.googleapis.com/maps/api/geocode/json?address={0}&sensor=false&language={1}".format(
            urllib.quote(location.encode("utf-8")), language
        )
        googleLocation = getNameFromGoogle(googleGuesser)
        if googleLocation != None:
            location = googleLocation

        self.logger.debug(u"User requested time in: {0}".format(location))
        # ask yahoo for a timezoneID
        query = u'select name from geo.places.belongtos where member_woeid in (select woeid from geo.places where text="{0}") and placetype=31'.format(
            location.encode("utf-8")
        )
        request = u"http://query.yahooapis.com/v1/public/yql?q={0}&format=json&callback=".format(
            urllib.quote(query.encode("utf-8"))
        )
        timeZoneId = None
        try:
            result = getWebsite(request, timeout=5)
            root = json.loads(result)
            place = root["query"]["results"]["place"]
            if type(place) == types.ListType:
                place = place[0]

            timeZoneId = place["name"]
        except:
            self.logger.exception("Error getting timezone")

        if timeZoneId == None:
            self.say(random.choice(localizations["failure"][language]))
            self.complete_request()
            return

        clock = ClockObject()
        clock.timezoneId = timeZoneId

        clockView = ClockSnippet()
        clockView.clocks = [clock]

        textView = UIAssistantUtteranceView()
        textView.listenAfterSpeaking = False
        textView.dialogIdentifier = "Clock#showTimeInOtherLocation"
        textView.text = textView.speakableText = random.choice(localizations["currentTimeIn"][language]).format(
            location, timeZoneId
        )

        rootAnchor = UIAddViews(self.refId)
        rootAnchor.dialogPhase = rootAnchor.DialogPhaseSummaryValue
        rootAnchor.scrollToTop = False
        rootAnchor.temporary = False
        rootAnchor.views = [textView, clockView]

        self.sendRequestWithoutAnswer(rootAnchor)
        self.complete_request()
コード例 #4
0
    def currentTime(self, speech, language):
        # first tell that we look it up
        self.showWait(language)

        textView = UIAssistantUtteranceView()
        textView.text = textView.speakableText = random.choice(localizations["currentTime"][language])
        textView.dialogIdentifier = "Clock#showTimeInCurrentLocation"
        textView.listenAfterSpeaking = False

        clock = ClockObject()
        clock.timezoneId = self.connection.assistant.timeZoneId

        clockView = ClockSnippet()
        clockView.clocks = [clock]

        rootAnchor = UIAddViews(self.refId)
        rootAnchor.dialogPhase = rootAnchor.DialogPhaseSummaryValue
        rootAnchor.views = [textView, clockView]

        self.sendRequestWithoutAnswer(rootAnchor)
        self.complete_request()
コード例 #5
0
    def currentTime(self, speech, language):
        #first tell that we look it up
        self.showWait(language)

        textView = UIAssistantUtteranceView()
        textView.text = textView.speakableText = random.choice(
            localizations["currentTime"][language])
        textView.dialogIdentifier = "Clock#showTimeInCurrentLocation"
        textView.listenAfterSpeaking = False

        clock = ClockObject()
        clock.timezoneId = self.connection.assistant.timeZoneId

        clockView = ClockSnippet()
        clockView.clocks = [clock]

        rootAnchor = UIAddViews(self.refId)
        rootAnchor.dialogPhase = rootAnchor.DialogPhaseSummaryValue
        rootAnchor.views = [textView, clockView]

        self.sendRequestWithoutAnswer(rootAnchor)
        self.complete_request()
コード例 #6
0
ファイル: timePlugin.py プロジェクト: waynesg511/SiriServer-1
    def currentTimeIn(self, speech, language):
        view = AddViews(self.refId, dialogPhase="Reflection")
        view.views = [
            AssistantUtteranceView(
                text=timePlugin.localizations['currentTimeIn']['search']
                [language],
                speakableText=timePlugin.localizations['currentTimeIn']
                ['search'][language],
                dialogIdentifier="Clock#getTime")
        ]
        self.sendRequestWithoutAnswer(view)

        error = False
        countryOrCity = re.match("(?u).* in ([\w ]+)$", speech, re.IGNORECASE)
        if countryOrCity != None:
            countryOrCity = countryOrCity.group(1).strip()
            # lets see what we got, a country or a city...
            # lets use google geocoding API for that
            url = u"http://maps.googleapis.com/maps/api/geocode/json?address={0}&sensor=false&language={1}".format(
                urllib.quote_plus(countryOrCity), language)
            # lets wait max 3 seconds
            jsonString = None
            try:
                jsonString = urllib2.urlopen(url, timeout=3).read()
            except:
                pass
            if jsonString != None:
                response = json.loads(jsonString)
                # lets see what we have...
                if response['status'] == 'OK':
                    components = response['results'][0]['address_components']
                    types = components[0][
                        'types']  # <- this should be the city or country
                    if "country" in types:
                        # OK we have a country as input, that sucks, we need the capital, lets try again and ask for capital also
                        components = filter(
                            lambda x: True
                            if "country" in x['types'] else False, components)
                        url = u"http://maps.googleapis.com/maps/api/geocode/json?address=capital%20{0}&sensor=false&language={1}".format(
                            urllib.quote_plus(components[0]['long_name']),
                            language)
                        # lets wait max 3 seconds
                        jsonString = None
                        try:
                            jsonString = urllib2.urlopen(url, timeout=3).read()
                        except:
                            pass
                        if jsonString != None:
                            response = json.loads(jsonString)
                            if response['status'] == 'OK':
                                components = response['results'][0][
                                    'address_components']
                # response could have changed, lets check again, but it should be a city by now
                if response['status'] == 'OK':
                    # get latitude and longitude
                    location = response['results'][0]['geometry']['location']
                    url = u"http://api.geonames.org/timezoneJSON?lat={0}&lng={1}&username={2}".format(
                        location['lat'], location['lng'], geonames_user)
                    jsonString = None
                    try:
                        jsonString = urllib2.urlopen(url, timeout=3).read()
                    except:
                        pass
                    if jsonString != None:
                        timeZoneResponse = json.loads(jsonString)
                        if "timezoneId" in timeZoneResponse:
                            timeZone = timeZoneResponse['timezoneId']
                            city = filter(
                                lambda x: True if "locality" in x['types'] or
                                "administrative_area_level_1" in x['types']
                                else False, components)[0]['long_name']
                            country = filter(
                                lambda x: True
                                if "country" in x['types'] else False,
                                components)[0]['long_name']
                            countryCode = filter(
                                lambda x: True
                                if "country" in x['types'] else False,
                                components)[0]['short_name']

                            view = AddViews(self.refId, dialogPhase="Summary")
                            view1 = AssistantUtteranceView(
                                text=timePlugin.localizations['currentTimeIn']
                                ['currentTimeIn']['text'][language].format(
                                    city, country, timeZone),
                                speakableText=timePlugin.
                                localizations['currentTimeIn']['currentTimeIn']
                                ['tts'][language].format(
                                    city, country, timeZone),
                                dialogIdentifier="Clock#showTimeInOtherLocation"
                            )
                            clock = ClockObject()
                            clock.timezoneId = timeZone
                            clock.countryCode = countryCode
                            clock.countryName = country
                            clock.cityName = city
                            clock.unlocalizedCityName = city
                            clock.unlocalizedCountryName = country
                            view2 = ClockSnippet(clocks=[clock])
                            view.views = [view1, view2]
                            self.sendRequestWithoutAnswer(view)
                        else:
                            error = True
                    else:
                        error = True
                else:
                    error = True
            else:
                error = True
        else:
            error = True
        if error:
            view = AddViews(self.refId, dialogPhase="Completion")
            view.views = [
                AssistantUtteranceView(
                    text=timePlugin.localizations['failure'][language],
                    speakableText=timePlugin.localizations['failure']
                    [language],
                    dialogIdentifier="Clock#cannotShowClocks")
            ]
            self.sendRequestWithoutAnswer(view)
        self.complete_request()
コード例 #7
0
ファイル: timePlugin.py プロジェクト: jonesgithub/SiriServer
 def currentTimeIn(self, speech, language):
     view = AddViews(self.refId, dialogPhase="Reflection")
     view.views = [AssistantUtteranceView(text=timePlugin.localizations['currentTimeIn']['search'][language], speakableText=timePlugin.localizations['currentTimeIn']['search'][language], dialogIdentifier="Clock#getTime")]
     self.sendRequestWithoutAnswer(view)
     
     error = False
     if language == 'zh-CN':
         countryOrCity = re.match(u"(?u).*现?在([\w ]+)(?:几点|时间).*", speech, re.IGNORECASE)
     else:
         countryOrCity = re.match(u"(?u).* (in|a|à|au|en) ([\w ]+)$", speech, re.IGNORECASE)
     if countryOrCity != None:
         countryOrCity = countryOrCity.group(countryOrCity.lastindex).strip()
         # lets see what we got, a country or a city... 
         # lets use google geocoding API for that
         url = u"http://maps.googleapis.com/maps/api/geocode/json?address={0}&sensor=false&language={1}".format(urllib.quote_plus(countryOrCity.encode("utf-8")), language)
         # lets wait max 3 seconds
         jsonString = None
         try:
             jsonString = urllib2.urlopen(url, timeout=3).read()
         except:
             pass
         if jsonString != None:
             response = json.loads(jsonString)
             # lets see what we have...
             if response['status'] == 'OK':
                 components = response['results'][0]['address_components']
                 types = components[0]['types'] # <- this should be the city or country
                 if "country" in types:
                     # OK we have a country as input, that sucks, we need the capital, lets try again and ask for capital also
                     components = filter(lambda x: True if "country" in x['types'] else False, components)
                     url = u"http://maps.googleapis.com/maps/api/geocode/json?address=capital%20{0}&sensor=false&language={1}".format(urllib.quote_plus(components[0]['long_name'].encode("utf-8")), language)
                         # lets wait max 3 seconds
                     jsonString = None
                     try:
                         jsonString = urllib2.urlopen(url, timeout=3).read()
                     except:
                         pass
                     if jsonString != None:
                         response = json.loads(jsonString)
                         if response['status'] == 'OK':
                             components = response['results'][0]['address_components']
             # response could have changed, lets check again, but it should be a city by now 
             if response['status'] == 'OK':
                 # get latitude and longitude
                 location = response['results'][0]['geometry']['location']
                 url = u"http://api.geonames.org/timezoneJSON?lat={0}&lng={1}&username={2}".format(location['lat'], location['lng'], geonames_user)
                 jsonString = None
                 try:
                     jsonString = urllib2.urlopen(url, timeout=3).read()
                 except:
                     pass
                 if jsonString != None:
                     timeZoneResponse = json.loads(jsonString)
                     if "timezoneId" in timeZoneResponse:
                         timeZone = timeZoneResponse['timezoneId']
                         city = filter(lambda x: True if "locality" in x['types'] or "administrative_area_level_1" in x['types'] else False, components)[0]['long_name']
                         country = filter(lambda x: True if "country" in x['types'] else False, components)[0]['long_name']
                         countryCode = filter(lambda x: True if "country" in x['types'] else False, components)[0]['short_name']
                         
                         view = AddViews(self.refId, dialogPhase="Summary")
                         view1 = AssistantUtteranceView(text=timePlugin.localizations['currentTimeIn']['currentTimeIn']['text'][language].format(city, country, timeZone), speakableText=timePlugin.localizations['currentTimeIn']['currentTimeIn']['tts'][language].format(city, country, timeZone), dialogIdentifier="Clock#showTimeInOtherLocation")
                         clock = ClockObject()
                         clock.timezoneId = timeZone
                         clock.countryCode = countryCode
                         clock.countryName = country
                         clock.cityName = city
                         clock.unlocalizedCityName = city
                         clock.unlocalizedCountryName = country
                         view2 = ClockSnippet(clocks=[clock])
                         view.views = [view1, view2]
                         self.sendRequestWithoutAnswer(view)
                     else:
                         error = True
                 else:
                     error = True
             else:
                 error = True
         else:
             error = True
     else:
         error = True
     if error:
         view = AddViews(self.refId, dialogPhase="Completion")
         view.views = [AssistantUtteranceView(text=timePlugin.localizations['failure'][language], speakableText=timePlugin.localizations['failure'][language], dialogIdentifier="Clock#cannotShowClocks")]
         self.sendRequestWithoutAnswer(view)
     self.complete_request()
コード例 #8
0
    def currentTimeIn(self, speech, language, matchedRegex):

        self.showWait(language)

        location = matchedRegex.group("loc")
        # ask google to enhance the request
        googleGuesser = "http://maps.googleapis.com/maps/api/geocode/json?address={0}&sensor=false&language={1}".format(
            urllib.quote(location.encode("utf-8")), language)
        googleLocation = getNameFromGoogle(googleGuesser)
        if googleLocation != None:
            location = googleLocation

        self.logger.debug(u"User requested time in: {0}".format(location))
        # ask yahoo for a timezoneID
        query = u"select name from geo.places.belongtos where member_woeid in (select woeid from geo.places where text=\"{0}\") and placetype=31".format(
            location.encode("utf-8"))
        request = u"http://query.yahooapis.com/v1/public/yql?q={0}&format=json&callback=".format(
            urllib.quote(query.encode("utf-8")))
        timeZoneId = None
        try:
            result = getWebsite(request, timeout=5)
            root = json.loads(result)
            place = root["query"]["results"]["place"]
            if type(place) == types.ListType:
                place = place[0]

            timeZoneId = place["name"]
        except:
            self.logger.exception("Error getting timezone")

        if timeZoneId == None:
            self.say(random.choice(localizations['failure'][language]))
            self.complete_request()
            return

        clock = ClockObject()
        clock.timezoneId = timeZoneId

        clockView = ClockSnippet()
        clockView.clocks = [clock]

        textView = UIAssistantUtteranceView()
        textView.listenAfterSpeaking = False
        textView.dialogIdentifier = "Clock#showTimeInOtherLocation"
        textView.text = textView.speakableText = random.choice(
            localizations["currentTimeIn"][language]).format(
                location, timeZoneId)

        rootAnchor = UIAddViews(self.refId)
        rootAnchor.dialogPhase = rootAnchor.DialogPhaseSummaryValue
        rootAnchor.scrollToTop = False
        rootAnchor.temporary = False
        rootAnchor.views = [textView, clockView]

        self.sendRequestWithoutAnswer(rootAnchor)
        self.complete_request()


## we should implement such a command if we cannot get the location however some structures are not implemented yet
#{"class"=>"AddViews",
#    "properties"=>
#        {"temporary"=>false,
#            "dialogPhase"=>"Summary",
#            "scrollToTop"=>false,
#            "views"=>
#                [{"class"=>"AssistantUtteranceView",
#                 "properties"=>
#                 {"dialogIdentifier"=>"Common#unresolvedExplicitLocation",
#                 "speakableText"=>
#                 "Ich weiß leider nicht, wo das ist. Wenn du möchtest, kann ich im Internet danach suchen.",
#                 "text"=>
#                 "Ich weiß leider nicht, wo das ist. Wenn du möchtest, kann ich im Internet danach suchen."},
#                 "group"=>"com.apple.ace.assistant"},
#                 {"class"=>"Button",
#                 "properties"=>
#                 {"commands"=>
#                 [{"class"=>"SendCommands",
#                  "properties"=>
#                  {"commands"=>
#                  [{"class"=>"StartRequest",
#                   "properties"=>
#                   {"handsFree"=>false,
#                   "utterance"=>
#                   "^webSearchQuery^=^Amerika^^webSearchConfirmation^=^Ja^"},
#                   "group"=>"com.apple.ace.system"}]},
#                  "group"=>"com.apple.ace.system"}],
#                 "text"=>"Websuche"},
#                 "group"=>"com.apple.ace.assistant"}]},
#    "aceId"=>"fbec8e13-5781-4b27-8c36-e43ec922dda3",
#    "refId"=>"702C0671-DB6F-4914-AACD-30E84F7F7DF3",
#    "group"=>"com.apple.ace.assistant"}
コード例 #9
0
ファイル: __init__.py プロジェクト: cedbv/SiriServer2
    def currentTimeIn(self, speech, language, matchedRegex):

        self.showWait(language)

        location = matchedRegex.group("loc")
        # ask google to enhance the request
        googleGuesser = "http://maps.googleapis.com/maps/api/geocode/json?address={0}&sensor=false&language={1}".format(urllib.quote(location.encode("utf-8")), language)
        googleLocation = getNameFromGoogle(googleGuesser)
        if googleLocation != None:
            location = googleLocation

        self.logger.debug(u"User requested time in: {0}".format(location))
        # ask yahoo for a timezoneID
        query = u"select name from geo.places.belongtos where member_woeid in (select woeid from geo.places where text=\"{0}\") and placetype=31".format(location.encode("utf-8"))
        request = u"http://query.yahooapis.com/v1/public/yql?q={0}&format=json&callback=".format(urllib.quote(query.encode("utf-8")))
        timeZoneId = None
        try:
            result = getWebsite(request, timeout=5)
            root = json.loads(result)
            place = root["query"]["results"]["place"]
            if type(place) == types.ListType:
                place = place[0]

            timeZoneId = place["name"]
        except:
            self.logger.exception("Error getting timezone")

        if timeZoneId == None:
            self.say(random.choice(localizations['failure'][language]))
            self.complete_request()
            return

        clock = ClockObject()
        clock.timezoneId = timeZoneId

        clockView = ClockSnippet()
        clockView.clocks = [clock]

        textView = UIAssistantUtteranceView()
        textView.listenAfterSpeaking = False
        textView.dialogIdentifier = "Clock#showTimeInOtherLocation"
        textView.text = textView.speakableText = random.choice(localizations["currentTimeIn"][language]).format(location, timeZoneId)

        rootAnchor = UIAddViews(self.refId)
        rootAnchor.dialogPhase = rootAnchor.DialogPhaseSummaryValue
        rootAnchor.scrollToTop = False
        rootAnchor.temporary = False
        rootAnchor.views = [textView, clockView]

        self.sendRequestWithoutAnswer(rootAnchor)
        self.complete_request()

## we should implement such a command if we cannot get the location however some structures are not implemented yet
#{"class"=>"AddViews",
#    "properties"=>
#        {"temporary"=>false,
#            "dialogPhase"=>"Summary",
#            "scrollToTop"=>false,
#            "views"=>
#                [{"class"=>"AssistantUtteranceView",
#                 "properties"=>
#                 {"dialogIdentifier"=>"Common#unresolvedExplicitLocation",
#                 "speakableText"=>
#                 "Ich weiß leider nicht, wo das ist. Wenn du möchtest, kann ich im Internet danach suchen.",
#                 "text"=>
#                 "Ich weiß leider nicht, wo das ist. Wenn du möchtest, kann ich im Internet danach suchen."},
#                 "group"=>"com.apple.ace.assistant"},
#                 {"class"=>"Button",
#                 "properties"=>
#                 {"commands"=>
#                 [{"class"=>"SendCommands",
#                  "properties"=>
#                  {"commands"=>
#                  [{"class"=>"StartRequest",
#                   "properties"=>
#                   {"handsFree"=>false,
#                   "utterance"=>
#                   "^webSearchQuery^=^Amerika^^webSearchConfirmation^=^Ja^"},
#                   "group"=>"com.apple.ace.system"}]},
#                  "group"=>"com.apple.ace.system"}],
#                 "text"=>"Websuche"},
#                 "group"=>"com.apple.ace.assistant"}]},
#    "aceId"=>"fbec8e13-5781-4b27-8c36-e43ec922dda3",
#    "refId"=>"702C0671-DB6F-4914-AACD-30E84F7F7DF3",
#    "group"=>"com.apple.ace.assistant"}