def locationFind(self, locationType): print locationType meSearch = ABPersonSearch(self.refId) meSearch.me = True meSearch.scope = "Local" answer = self.getResponseForRequest(meSearch) if ObjectIsCommand(answer, ABPersonSearchCompleted): results = ABPersonSearchCompleted(answer) persons = results.results identfind = results.results[0] contactIdentifier = identfind.identifier me = persons[0] Addresses = filter(lambda x: x.label == locationType, me.addresses) if len(Addresses) > 0: Result = Addresses[0] Street = Result.street PostalCode = Result.postalCode City = Result.city Title = "{0}, {1}, {2}".format(Street, City, PostalCode) Query = urllib.quote_plus(str(Title.encode("utf-8"))) googleurl = "http://maps.googleapis.com/maps/api/geocode/json?address={0}&sensor=true".format(Query) jsonString = urllib2.urlopen(googleurl, timeout=20).read() response = json.loads(jsonString) if (response['status'] == 'OK') and (len(response['results'])): for result in response['results']: latitude=result['geometry']['location']['lat'] longitude=result['geometry']['location']['lng'] stateCode=result['address_components'][4]['long_name'] countryCode=result['address_components'][5]['long_name'] Location = [latitude, longitude, Street, City, PostalCode, stateCode, countryCode, contactIdentifier] return Location else: return
def searchUserByName(self, personToLookup): search = ABPersonSearch(self.refId) search.scope = ABPersonSearch.ScopeLocalValue search.name = personToLookup answerObj = self.getResponseForRequest(search) if ObjectIsCommand(answerObj, ABPersonSearchCompleted): answer = ABPersonSearchCompleted(answerObj) return answer.results if answer.results != None else [] else: raise StopPluginExecution("Unknown response: {0}".format(answerObj)) return []
def changeName(self, nameType, value): meSearch = ABPersonSearch(self.refId) meSearch.me = True meSearch.scope = "Local" answer = self.getResponseForRequest(meSearch) if ObjectIsCommand(answer, ABPersonSearchCompleted): results = ABPersonSearchCompleted(answer) results = results.results[0] else: raise StopPluginExecution("Unknown response: {0}".format(answer)) mePerson = ABPerson() mePerson.identifier = results.identifier domainRetrieve = DomainObjectRetrieve(self.refId) domainRetrieve.identifiers = [mePerson] domainAnswer = self.getResponseForRequest(domainRetrieve) if not ObjectIsCommand(domainAnswer, DomainObjectRetrieveCompleted): raise StopPluginExecution("Unknown response: {0}".format(domainAnswer)) domainUpdate = DomainObjectUpdate(self.refId) domainUpdate.identifier = mePerson newName = ABPerson() if nameType in ["nick", "nick name"]: newName.nickName = value if nameType in ["firstName", "first name"]: newName.firstName = value if nameType in ["lastName", "last name"]: newName.lastName = value domainUpdate.setFields = newName updateAnswer = self.getResponseForRequest(domainUpdate) if not ObjectIsCommand(updateAnswer, DomainObjectUpdateCompleted): raise StopPluginExecution("Unknown response: {0}".format(updateAnswer)) domainCommit = DomainObjectCommit(self.refId) domainCommit.identifier = mePerson commitAnswer = self.getResponseForRequest(domainCommit) if not ObjectIsCommand(commitAnswer, DomainObjectCommitCompleted): raise StopPluginExecution("Unknown response: {0}".format(commitAnswer))