
import datetime
import requests

FORMAT_STRING = "%Y%m%d%H%M%S"  # Looks like "20130919044612"
AVAILABILITY_URL = "http://archive.org/wayback/available?url=%s"


def availability(url):
    response = requests.get(AVAILABILITY_URL % (url))
    print(response)
    print(response.text)
    response_j = response.json()
    if response_j.get('archived_snapshots') == {}:
        return None
    else:
        closest = response_j.get('archived_snapshots').get('closest')
        avail = closest.get('available')
        status = int(closest.get('status'))
        timestamp = closest.get('timestamp')
        timestamp = datetime.datetime.strptime(timestamp, FORMAT_STRING)
        url = closest.get('url')
    return {'verbatim': closest, 'url': url, 'timestamp': timestamp}


import datetime
import requests

FORMAT_STRING = "%Y%m%d%H%M%S"  # Looks like "20130919044612"
AVAILABILITY_URL = "http://archive.org/wayback/available?url=%s"
WAYBACK_URL_ROOT = "http://web.archive.org"


def availability(url):
    response = requests.get(AVAILABILITY_URL % (url))
    print(response)
    print(response.text)
    response_j = response.json()
    if response_j.get('archived_snapshots') == {}:
        return None
    else:
        closest = response_j.get('archived_snapshots').get('closest')
        avail = closest.get('available')
        status = int(closest.get('status'))
        timestamp = closest.get('timestamp')
        timestamp = datetime.datetime.strptime(timestamp, FORMAT_STRING)
        url = closest.get('url')
    return {'verbatim': closest, 'url': url, 'timestamp': timestamp}

Add a constant for WB root URL
Add a constant for WB root URL

  
  import datetime
  import requests
  
  FORMAT_STRING = "%Y%m%d%H%M%S"  # Looks like "20130919044612"
  AVAILABILITY_URL = "http://archive.org/wayback/available?url=%s"
+ WAYBACK_URL_ROOT = "http://web.archive.org"
  
  
  def availability(url):
      response = requests.get(AVAILABILITY_URL % (url))
      print(response)
      print(response.text)
      response_j = response.json()
      if response_j.get('archived_snapshots') == {}:
          return None
      else:
          closest = response_j.get('archived_snapshots').get('closest')
          avail = closest.get('available')
          status = int(closest.get('status'))
          timestamp = closest.get('timestamp')
          timestamp = datetime.datetime.strptime(timestamp, FORMAT_STRING)
          url = closest.get('url')
      return {'verbatim': closest, 'url': url, 'timestamp': timestamp}
  
Add a constant for WB root URL
## Code Before:

import datetime
import requests

FORMAT_STRING = "%Y%m%d%H%M%S"  # Looks like "20130919044612"
AVAILABILITY_URL = "http://archive.org/wayback/available?url=%s"


def availability(url):
    response = requests.get(AVAILABILITY_URL % (url))
    print(response)
    print(response.text)
    response_j = response.json()
    if response_j.get('archived_snapshots') == {}:
        return None
    else:
        closest = response_j.get('archived_snapshots').get('closest')
        avail = closest.get('available')
        status = int(closest.get('status'))
        timestamp = closest.get('timestamp')
        timestamp = datetime.datetime.strptime(timestamp, FORMAT_STRING)
        url = closest.get('url')
    return {'verbatim': closest, 'url': url, 'timestamp': timestamp}

## Instruction:
Add a constant for WB root URL
## Code After:

import datetime
import requests

FORMAT_STRING = "%Y%m%d%H%M%S"  # Looks like "20130919044612"
AVAILABILITY_URL = "http://archive.org/wayback/available?url=%s"
WAYBACK_URL_ROOT = "http://web.archive.org"


def availability(url):
    response = requests.get(AVAILABILITY_URL % (url))
    print(response)
    print(response.text)
    response_j = response.json()
    if response_j.get('archived_snapshots') == {}:
        return None
    else:
        closest = response_j.get('archived_snapshots').get('closest')
        avail = closest.get('available')
        status = int(closest.get('status'))
        timestamp = closest.get('timestamp')
        timestamp = datetime.datetime.strptime(timestamp, FORMAT_STRING)
        url = closest.get('url')
    return {'verbatim': closest, 'url': url, 'timestamp': timestamp}
