import json


def has_tweeted_pet_already(pet_url, tweeted_path='.tweeted.json'):
    """Check if an item has already been tweeted.
    
    If not, the item is added to the "already tweeted" list.
    
    Parameters
    ----------
    pet_url : str
        The url of the item that is being checked. Acts like a UUID.
    tweeted_path : str, default to ``.tweeted.json``
        The .json file aka the "already tweeted" list.
        
    Returns
    -------
    ``True`` is the url is in the "already tweeted" list.
    ``False`` otherwise.
    
    """
    
    try:
        with open(tweeted_path) as already_tweeted:
            data = json.loads(already_tweeted.read())
    except IOError:
        data = {'tweeted': []}

    if pet_url in data['tweeted']:
        return True
    else:
        data['tweeted'].append(pet_url)
        with open(tweeted_path, 'w+') as already_tweeted:
            already_tweeted.write(json.dumps(data))
        return False