Skip to content

Commit

Permalink
Merge pull request #26 from hifis-net/fix_organisation_id
Browse files Browse the repository at this point in the history
Fix retrieval of org_id
  • Loading branch information
cmeessen authored Feb 7, 2023
2 parents 7e05138 + 780829d commit 493721c
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,8 +457,21 @@ async def get_id_for_organisation(client, org):
return None


async def organisation_has_logo(client, org) -> bool:
org_id = await get_id_for_organisation(client, org)
async def get_organisation_id_by_ror(client, ror):
res = (
await client.from_("organisation")
.select("id", "ror_id")
.eq("ror_id", f"https://ror.org/{ror}")
.execute()
)

if len(res.data) > 0:
return res.data[0].get("id")

return None


async def organisation_has_logo(client, org_id) -> bool:
res = (
await client.from_("organisation")
.select("id", "logo_id")
Expand Down Expand Up @@ -487,7 +500,7 @@ async def add_organisations(client, spotlight):
logging.info("Add organisations for %s", name)

for org in orgs:
org_id = await get_id_for_organisation(client, org)
org_id = await get_organisation_id_by_ror(client, ORGANISATIONS.get(org).get("ror"))

if org_id is None:
logging.info("Adding organisation %s" % org)
Expand All @@ -507,7 +520,7 @@ async def add_organisations(client, spotlight):

org_id = await get_id_for_organisation(client, org)

logo_exists = await organisation_has_logo(client, org)
logo_exists = await organisation_has_logo(client, org_id)
logo_available = (
org in ORGANISATIONS.keys() and "logo" in ORGANISATIONS.get(org).keys()
)
Expand Down

0 comments on commit 493721c

Please sign in to comment.