Skip to content

Commit

Permalink
Added whereAmI plugin, thx to john-dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Eichhoernchen authored and Eichhoernchen committed Feb 12, 2012
1 parent 1ef4b65 commit 36360a2
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
1 change: 1 addition & 0 deletions plugins.conf
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ timePlugin
wordnikDefinitions
examplePlugin
wwwsearch
whereAmI
displaypicture
XBMC
notes
Expand Down
63 changes: 63 additions & 0 deletions plugins/whereAmI.py
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()

0 comments on commit 36360a2

Please sign in to comment.