from datetime import datetime
import requests


def get_weather(date: datetime, lat, long, secret_key,
                base_url='https://api.darksky.net/forecast/', 
                exclusions="?exclude=currently,minutely,hourly,alerts,flags", 
                collection=None):
    """Retrieve weather for a particular date based on exclusions passed.
    Stores weather in mongoDB collection passed
    
    Args:
        date: datetime object
        lat: latitude of interest
        long: longitude of interest
        base_url: the base url of the weather api (default: darksky)
        exclusions: list of exclusions to pass to the api
        secret_key: your secret key to access the weather api
        collection: the MongoDB collection you would like to store the weather
            data in

    Returns:
        If no MongoDB collection, returns weather json.
        Else, data is stored in the collection passed.
    """
    date_str = date.strftime('%Y-%m-%d') + 'T12:00:00'
    url = f"{base_url}{secret_key}/{lat},{long},{date_str}{exclusions}"
    response = requests.get(url)
    output = response.json()
    output['date'] = date
    if collection == None:
        return output
    collection.insert_one(output)