diff --git a/plugins.conf b/plugins.conf index b8d731f..f1c695b 100644 --- a/plugins.conf +++ b/plugins.conf @@ -11,6 +11,7 @@ timePlugin wordnikDefinitions examplePlugin wwwsearch +whereAmI displaypicture XBMC notes diff --git a/plugins/whereAmI.py b/plugins/whereAmI.py new file mode 100644 index 0000000..09e2af0 --- /dev/null +++ b/plugins/whereAmI.py @@ -0,0 +1,63 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- + +#need help? ask john-dev + +import re +import urllib2, urllib +import json + +from plugin import * + +from siriObjects.baseObjects import AceObject, ClientBoundCommand +from siriObjects.systemObjects import GetRequestOrigin +from siriObjects.uiObjects import AddViews, AssistantUtteranceView +from siriObjects.mapObjects import SiriLocation, SiriMapItem, SiriMapItemSnippet + +geonames_user="test2" + +class whereAmI(Plugin): + + @register("de-DE", "(Wo bin ich.*)") + @register("en-US", "(Where am I.*)") + def whereAmI(self, speech, language): + mapGetLocation = self.getCurrentLocation() + latitude = mapGetLocation.latitude + longitude = mapGetLocation.longitude + url = "http://maps.googleapis.com/maps/api/geocode/json?latlng={0},{1}&sensor=false&language={2}".format(str(latitude),str(longitude), language) + 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'] + street = filter(lambda x: True if "route" in x['types'] else False, components)[0]['long_name'] + stateLong= filter(lambda x: True if "administrative_area_level_1" in x['types'] or "country" in x['types'] else False, components)[0]['long_name'] + postalCode= filter(lambda x: True if "postal_code" in x['types'] else False, components)[0]['long_name'] + try: + city = filter(lambda x: True if "locality" in x['types'] or "administrative_area_level_1" in x['types'] else False, components)[0]['long_name'] + except: + city="" + countryCode = filter(lambda x: True if "country" in x['types'] else False, components)[0]['short_name'] + view = AddViews(self.refId, dialogPhase="Completion") + if language == "de-DE": + the_header="Dein Standort" + else: + the_header="Your location" + Location=SiriLocation(the_header, street, city, stateLong, countryCode, postalCode, latitude, longitude) + mapsnippet = SiriMapItemSnippet(items=[SiriMapItem(the_header, Location)]) + view.views = [AssistantUtteranceView(text=the_header, dialogIdentifier="Map"), mapsnippet] + self.sendRequestWithoutAnswer(view) + else: + if language=="de-DE": + self.say('Die Googlemaps informationen waren ungenĂ¼gend!','Fehler') + else: + self.say('The Googlemaps response did not hold the information i need!','Error') + else: + if language=="de-DE": + self.say('Ich konnte keine Verbindung zu Googlemaps aufbauen','Fehler') + else: + self.say('Could not establish a conenction to Googlemaps','Error'); + self.complete_request()