import requests
import json


def warc_url(url):
    """
    Search the WARC archived version of the URL

    :returns: The WARC URL if found, else None
    """
    query = "http://archive.org/wayback/available?url={}".format(url)

    response = requests.get(query)

    if not response:
        raise RuntimeError()

    data = json.loads(response.text)
    snapshots = data["archived_snapshots"]

    if not snapshots:
        return None

    return snapshots["closest"]["url"]