def get_person(url): if (url is None or len(url) < 1): return None person = None try: person = db.open().query(Person).filter(Person.api_url == url).one() except NoResultFound: pass except Exception as exp: print(exp) pass if (person is None): json_dict = get_json_dict(url) if (json_dict is not None and 'url' in json_dict): person = Person() person.parse_dict(json_dict) try: db.save(person) except Exception as exp: print(exp) planet = get_planet(json_dict['homeworld']) if (planet is not None): person.planet = planet try: db.save(person) except Exception as exp: print(exp) for starship_url in json_dict['starships']: starship = get_starship(starship_url) persist_pilot(person, starship) for vehicle_url in json_dict['vehicles']: vehicle = get_vehicle(vehicle_url) persist_driver(person, vehicle) return person