def find_by_id(self, type_id): session = Session() try: habitat_type = session.query(HabitatType).filter( HabitatType.type_id == type_id).one() except: habitat_type = None finally: session.close() return habitat_type
def get_species(self): session = Session() try: species = session.query(DbSpecies).filter( DbSpecies.species_id == self.species_id).one() except: species = None finally: session.close() return species
def find(self, species_name): session = Session() try: species = session.query(DbSpecies).filter( DbSpecies.name == species_name).one() except: species = None finally: session.close() return species
def find_by_id(self, type_id): session = Session() try: habitat_type = session.query(HabitatType).filter( HabitatType.type_id == type_id ).one() except: habitat_type = None finally: session.close() return habitat_type
def get_species(self): session = Session() try: species = session.query(DbSpecies).filter( DbSpecies.species_id == self.species_id ).one() except: species = None finally: session.close() return species
def find(self, species_name): session = Session() try: species = session.query(DbSpecies).filter( DbSpecies.name == species_name ).one() except: species = None finally: session.close() return species
def get_associated_habitat_types(self): session = Session() try: species_habitat_links = session.query(HabitatTypesSpecies).filter( HabitatTypesSpecies.species_id == self.species_id).all() type_ids = [lnk.type_id for lnk in species_habitat_links] habitat_types = session.query(HabitatType).filter( HabitatType.type_id.in_(type_ids)).all() except: habitat_types = None finally: session.close() return habitat_types
def get_typical_species(self): session = Session() try: habitat_species_links = session.query(HabitatTypesSpecies).filter( HabitatTypesSpecies.type_id == self.type_id).all() species_ids = [lnk.species_id for lnk in habitat_species_links] species = session.query(Species).filter( Species.species_id.in_(species_ids)).all() except: species = None finally: session.close() return species
def get_associated_habitat_types(self): session = Session() try: species_habitat_links = session.query(HabitatTypesSpecies).filter( HabitatTypesSpecies.species_id == self.species_id ).all() type_ids = [lnk.type_id for lnk in species_habitat_links] habitat_types = session.query(HabitatType).filter( HabitatType.type_id.in_(type_ids) ).all() except: habitat_types = None finally: session.close() return habitat_types
def get_typical_species(self): session = Session() try: habitat_species_links = session.query(HabitatTypesSpecies).filter( HabitatTypesSpecies.type_id == self.type_id ).all() species_ids = [lnk.species_id for lnk in habitat_species_links] species = session.query(Species).filter( Species.species_id.in_(species_ids) ).all() except: species = None finally: session.close() return species
def find_by_name(self, name): session = Session() try: species = session.query(Species).filter(Species.name == name).one() except: # finding species spf = SpeciesFinder(name) sp_name, sp_url, sp_info = spf.find_species() # creating new species species = Species(sp_name, sp_url, sp_info) # adding species to database session.merge(species) session.commit() finally: session.close() return species
def find_by_name(self, name): session = Session() try: species = session.query(Species).filter( Species.name == name ).one() except: # finding species spf = SpeciesFinder(name) sp_name, sp_url, sp_info = spf.find_species() # creating new species species = Species(sp_name, sp_url, sp_info) # adding species to database session.merge(species) session.commit() finally: session.close() return species