def get_person(self): """ Lazy instantiation of property - will fetch from Highrise. NB This may result in a network API call. """ if self._person is None: if self.highrise_id is None: return None else: self._person = Person.get(self.highrise_id) return self._person
def run(): """ Pulls down all people and companies in the highrise account specified by the HIGHRISE_SERVER and HIGHRISE_AUTH_TOKEN env vars and returns a dictionary in the format: { <id>: { 'name': <name> 'lat': <lat>, 'lng': <lng> }, ... } """ HIGHRISE_SERVER = os.environ.get('HIGHRISE_SERVER') HIGHRISE_AUTH_TOKEN = os.environ.get('HIGHRISE_AUTH_TOKEN') if not HIGHRISE_SERVER and HIGHRISE_AUTH_TOKEN: raise Exception( 'HIGHRISE_SERVER and HIGHRISE_AUTH_TOKEN are required env vars' ) Highrise.set_server(HIGHRISE_SERVER) Highrise.auth(HIGHRISE_AUTH_TOKEN) gn = geocoders.GeoNames() data = {} for x in Person.all() + Company.all(): cd = x.contact_data zipcode = None if cd.addresses: a = cd.addresses[0] zipcode = a.zip if zipcode: if type(x) == Person: name = '%s %s (%s)' % (x.first_name, x.last_name, x.company_name) elif type(x) == Company: name = x.name try: print 'Finding lat/lng for %s' % name place, (lat,lng) = gn.geocode(zipcode) data[x.id] = {'name': name, 'lat': lat, 'lng': lng} except Exception: pass return data
# identify header row header = next(csvFile) # loop rows in csv file, and identify variables for fields, you will need to know which index contains the tag you want. for row in csvFile: if len(row) < 21: # use if final column can be blank continue tag1 = row[0] # Yes or No tag2 = row[1] address = row[2] # Email address (required to lookup) tag3 = row[10] # multiple choice tag4 = row[20] # final column, free-text so might be empty # if a column contains multiple choice, use regex to search for the choice you want to tag on (e.g. I like: red, white, green; search for green to tag: 'likes green') green = re.search("green", tag3) # if a person has an email address, use the Person.filter to identify the addresses, and add tags to accounts mapped to the address. if address: people = Person.filter(email=address) for i in people: if tag1 == "Yes": i.add_tag("tag one") i.save() i.add_tag("text " + tag2) i.add_note(tag4) if green: i.add_tag("likes green")
def highrise_import_tasks_of_person(cls, id): person = Person.get(id) tasks = person.tasks return tasks
def highrise_import_tags_of_person(cls, request): person = Person.get(request.id) tags = person.tags return tags
def highrise_import_notes_of_person(cls, id): person = Person.get(id) notes = person.notes return notes
def highrise_import_peoples(cls, request): people = Person.all() return people