import json
import requests


def collection_exists(collection_name):
    """
    Check if a collection already exists on DIVAServices

    Arguments:
        collection_name {string} -- the name of the collection on DIVAServices

    Returns:
        bool -- True if the collection exists, False otherwise
    """

    url = "http://divaservices.unifr.ch/api/v2/collections/" + collection_name
    payload = ""
    response = json.loads(requests.request("GET", url, data=payload).text)
    return 'statusCode' in response and response['statusCode'] == 200