import requests
import json


def get_wikidata_id(article):
    """Find the Wikidata ID for a given Wikipedia article."""
    query_string = "https://de.wikipedia.org/w/api.php?action=query&prop=pageprops&ppprop=wikibase_item&redirects=1&format=json&titles=%s" % article

    ret_val = requests.get(query_string).text

    pprops = json.loads(ret_val)

    if pprops["query"]["pages"]:
        for _, data in pprops["query"]["pages"].items():
            wikidata_id = data["pageprops"]["wikibase_item"]
            return wikidata_id
    else:
        print("No page returned.")