From cd4efb58a913510ea3c4ad3511569f2feafe093e Mon Sep 17 00:00:00 2001 From: "J. Alvarez-Jarreta" Date: Thu, 19 Oct 2023 10:43:19 +0100 Subject: [PATCH 1/2] handle case where nothing is found Example: searching for `homo` --- src/taxon_search/views.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/taxon_search/views.py b/src/taxon_search/views.py index 6847488..7bdf864 100644 --- a/src/taxon_search/views.py +++ b/src/taxon_search/views.py @@ -35,8 +35,8 @@ def index(request): # call the elastic search function in search.py search_results = search_species(q) - name_class = [d["name_class"] for d in search_results][0] - rank = [d["rank"] for d in search_results][0] + name_class = [d["name_class"] for d in search_results][0] if search_results else "" + rank = [d["rank"] for d in search_results][0] if search_results else "" matched_species = set([d["species_taxon_id"] for d in search_results]) species_names = EnsemblMetadata.objects.filter(taxonomy_id__in=matched_species) From 88adb898cda2529be91e806e992e4851c26bd290 Mon Sep 17 00:00:00 2001 From: "J. Alvarez-Jarreta" Date: Thu, 19 Oct 2023 10:46:31 +0100 Subject: [PATCH 2/2] set default url param value --- scripts/get_taxon_flat.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/scripts/get_taxon_flat.py b/scripts/get_taxon_flat.py index fb4e975..8ee100e 100644 --- a/scripts/get_taxon_flat.py +++ b/scripts/get_taxon_flat.py @@ -8,7 +8,7 @@ pymysql.install_as_MySQLdb() -def get_taxon_ids(url): +def get_taxon_ids(species_url: str = "https://metazoa.ensembl.org/species.html"): """ The function scrapes the metazoa taxonomy ids data from a fixed url: https://metazoa.ensembl.org/species.html @@ -19,7 +19,6 @@ def get_taxon_ids(url): """ - species_url = "https://metazoa.ensembl.org/species.html" response = requests.get(species_url) soup = BeautifulSoup(response.text, "lxml")