Skip to content

Commit

Permalink
Merge pull request #11 from hifis-net/3-organisation_logos
Browse files Browse the repository at this point in the history
Adds organisation logos
  • Loading branch information
cmeessen authored Jul 26, 2022
2 parents 44cf72a + 8f12329 commit f7d6aed
Show file tree
Hide file tree
Showing 12 changed files with 519 additions and 5 deletions.
60 changes: 57 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import re
import glob
import logging
import base64
import magic

import yaml
import jwt
Expand All @@ -28,6 +30,21 @@
JWT_ALGORITHM = "HS256"
SPOTLIGHTS_DIR = "hifis.net/_spotlights"

ORGANISATION_LOGOS = {
"Helmholtz Centre for Environmental Research (UFZ)": "UFZ.svg",
"Helmholtz Centre Potsdam GFZ German Research Centre for Geosciences": "GFZ.svg",
"German Aerospace Center (DLR)": "DLR.svg",
"Alfred Wegener Institute for Polar and Marine Research (AWI)": "AWI.svg",
"Karlsruhe Institute of Technology (KIT)": "KIT.svg",
"CISPA Helmholtz Center for Information Security": "CISPA.png",
"Helmholtz Centre for Heavy Ion Research (GSI)": "GSI.svg",
"Helmholtz Centre For Ocean Research Kiel (GEOMAR)": "GEOMAR.jpg",
"Helmholtz-Zentrum Dresden-Rossendorf (HZDR)": "HZDR.png",
}
MISSING_LOGOS = []

mime = magic.Magic(mime=True)


def get_md_without_front_matter(file):
found = 0
Expand Down Expand Up @@ -413,6 +430,34 @@ async def add_organisations(client, spotlight):

org_id = await get_id_for_organisation(client, org)

if not org in ORGANISATION_LOGOS.keys():
logging.warn("No logo found for %s" % org)
MISSING_LOGOS.append(org)
else:
logo_db = (
await client.from_("logo_for_organisation")
.select("*")
.eq("organisation", org_id)
.execute()
)
if len(logo_db.data) == 0:
logo_filename = f"./resources/logos/{ORGANISATION_LOGOS[org]}"
logging.info("Adding logo %s" % logo_filename)
with open(logo_filename, "rb") as logo:
logo_base64 = base64.b64encode(logo.read()).decode("utf-8")
mime_type = mime.from_file(logo_filename)
logo_data = {
"organisation": org_id,
"data": logo_base64,
"mime_type": mime_type,
}
res = (
await client.from_("logo_for_organisation")
.insert(logo_data)
.execute()
)
logging.info(res.data)

logging.info("Adding organisation %s to software %s" % (org, name))

res = (
Expand Down Expand Up @@ -462,7 +507,7 @@ async def add_research_field(client, spotlight):


async def process_imprint(client):
filename ="./resources/Imprint.md"
filename = "./resources/Imprint.md"
with open(filename, "r") as imprint:
logging.info("Processing imprint from %s", filename)

Expand All @@ -474,9 +519,14 @@ async def process_imprint(client):
"position": 1,
}

db_imprint = await client.from_("meta_pages").select("*").eq("slug","imprint").execute()
db_imprint = (
await client.from_("meta_pages")
.select("*")
.eq("slug", "imprint")
.execute()
)

if (len(db_imprint.data) > 0):
if len(db_imprint.data) > 0:
logging.info("Imprint already exsits. Updating.")
res = await client.from_("meta_pages").update(data).execute()
else:
Expand Down Expand Up @@ -514,6 +564,10 @@ async def main():
print("The following spotlights were skipped:")
for name, reason in skipped:
print(" %s: %s" % (name, reason))
if len(MISSING_LOGOS) > 0:
print("There were logos missing of the following organisations:")
for org in MISSING_LOGOS:
print(" %s" % org)


if __name__ == "__main__":
Expand Down
13 changes: 11 additions & 2 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ python = ">=3.8; <3.11"
postgrest-py = "^0.10.2"
pyyaml = "^6.0"
PyJWT = "^2.4.0"
python-magic = "^0.4.27"

[tool.poetry.dev-dependencies]
black = "^22.3.0"
24 changes: 24 additions & 0 deletions resources/logos/AWI.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/logos/CISPA.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 39 additions & 0 deletions resources/logos/DLR.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/logos/GEOMAR.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit f7d6aed

Please sign in to comment.