-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added whereAmI plugin, thx to john-dev
- Loading branch information
Eichhoernchen
authored and
Eichhoernchen
committed
Feb 12, 2012
1 parent
1ef4b65
commit 36360a2
Showing
2 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ timePlugin | |
wordnikDefinitions | ||
examplePlugin | ||
wwwsearch | ||
whereAmI | ||
displaypicture | ||
XBMC | ||
notes | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |