예제 #1
0
def get_astral_data(for_datetime):
    '''
    Returns the sunrise and sunset times for the given date.
    Uses the Astral package to compute sunrise/sunset for the
    configured city.
    Reference https://pythonhosted.org/astral/module.html
    :param for_datetime:
    :return: Returns a dict containing the keys sunrise and sunset.
    The values are datetime objects.
    '''
    a = Astral()
    a.solar_depression = "civil"
    # We use a city just to get a city object. Then we override the lat/long.
    # The city object can produce sunrise/sunset in local time.
    if Configuration.City() != "":
        city = a[Configuration.City()]
    else:
        # Default if no city is configured
        city = a["New York"]
    if Configuration.Latitude() != "":
        city.latitude = float(Configuration.Latitude())
    if Configuration.Longitude() != "":
        city.longitude = float(Configuration.Longitude())

    return city.sun(date=for_datetime, local=True)
예제 #2
0
def get_location():
    """
    Returns the location as configured
    :return:
    """
    resp = {
        "latitude": Configuration.Latitude(),
        "longitude": Configuration.Longitude()
    }
    return jsonify(resp)