import requests
import json


def getredirect(pagename):
    """Given a wikipedia page name, if the page name refers to a redirect, returns the name of the 
    page that the redirect points to; Otherwise, returns the input

    :param pagename: The name of a wikipedia page
    :type pagename: String
    
    :return: The absolute name of the page pointed to by pagename
    :rtype: String
    """
    pagenamehyphen = pagename.replace(' ', '_')
    query = requests.get(f'https://en.wikipedia.org/w/api.php?action=query&titles={pagenamehyphen}&&redirects&format=json')
    data = json.loads(query.text)
    if 'redirects' in data['query']:
        return data['query']['redirects'][0]['to']
    else:
        return pagename