Skip to content

Commit

Permalink
Merge pull request #1193 from microbiomedata/improve-image_handling
Browse files Browse the repository at this point in the history
Store PI image url on ingest and log request errors
  • Loading branch information
marySalvi authored Mar 22, 2024
2 parents ebd3860 + 4fc9e21 commit d1a0bb5
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions nmdc_server/ingest/study.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@
from nmdc_server.crud import create_study, get_doi
from nmdc_server.ingest.common import extract_extras, extract_value
from nmdc_server.ingest.doi import upsert_doi
from nmdc_server.logger import get_logger
from nmdc_server.models import PrincipalInvestigator
from nmdc_server.schemas import StudyCreate

logger = get_logger(__name__)


def get_or_create_pi(db: Session, name: str, url: Optional[str], orcid: Optional[str]) -> str:
pi = db.query(PrincipalInvestigator).filter_by(name=name).first()
Expand All @@ -23,6 +26,8 @@ def get_or_create_pi(db: Session, name: str, url: Optional[str], orcid: Optional
r = requests.get(url)
if r.ok:
image_data = r.content
else:
logger.error(f"Failed to download image for {name} from {url} : {r.status_code}")

pi = PrincipalInvestigator(name=name, image=image_data, orcid=orcid)

Expand Down Expand Up @@ -64,6 +69,7 @@ def load(db: Session, cursor: Cursor):
pi_orcid = pi_obj.get("orcid")
obj["principal_investigator_id"] = get_or_create_pi(db, pi_name, pi_url, pi_orcid)
obj["principal_investigator_websites"] = obj.pop("websites", [])
obj["pricipal_investigator_image_url"] = pi_url
obj["image"] = get_study_image_data(obj.pop("study_image", []))
dois = obj.pop("associated_dois", None)
if dois:
Expand Down

0 comments on commit d1a0bb5

Please sign in to comment.