コード例 #1
0
 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
コード例 #2
0
ファイル: db_n2k.py プロジェクト: leaffan/geo
 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
コード例 #3
0
ファイル: db_n2k.py プロジェクト: leaffan/geo
 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
コード例 #4
0
ファイル: n2k.py プロジェクト: leaffan/geo
 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
コード例 #5
0
ファイル: db_n2k.py プロジェクト: leaffan/geo
 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
コード例 #6
0
ファイル: db_n2k.py プロジェクト: leaffan/geo
 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
コード例 #7
0
 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
コード例 #8
0
 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
コード例 #9
0
ファイル: n2k.py プロジェクト: leaffan/geo
 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
コード例 #10
0
ファイル: n2k.py プロジェクト: leaffan/geo
 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
コード例 #11
0
 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
コード例 #12
0
ファイル: n2k.py プロジェクト: leaffan/geo
 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