import hashlib


def get_image_url_by_name(image_name: str) -> str:
    """Calculate the image url from the image name

    This is done via the MD5 hash of the image_names hex-code.

    Source:
        https://stackoverflow.com/questions/34393884/how-to-get-image-url-property-from-wikidata-item-by-api

    Args:
        image_name: image name returned from the wikidata API call

    Returns:
        URL of the image
    """
    image_name = image_name.replace(" ", "_")
    hash = hashlib.md5(image_name.encode("utf-8", errors="replace")).hexdigest()
    hash_index_1 = hash[0]
    hash_index_1_and_2 = hash[0] + hash[1]
    url = "https://upload.wikimedia.org/wikipedia/commons/{0}/{1}/{2}".format(
        hash_index_1, hash_index_1_and_2, image_name
    )
    return url