def verify_earthquake():
    """
    Verify earthquake using USGS service.
    """

    geo_lat = APP_CONFIG.latitude
    geo_long = APP_CONFIG.longitude

    server = "http://earthquake.usgs.gov/fdsnws/event/1/query"

    time_window = datetime.utcnow() - timedelta(minutes=10)

    query = {
        "format": "geojson",
        "starttime": time_window.isoformat(),
        "latitude": geo_lat,
        "longitude": geo_long,
        "maxradiuskm": 500
    }

    print("Calling USGS service.")
    response = get_http(server, params=query)
    response.raise_for_status()
    data = response.json()
    event_count = len(data["features"])
    return True if event_count > 0 else False
def verify_earthquake():

    """
    Verify earthquake using USGS service.
    """

    geo_lat = APP_CONFIG.latitude
    geo_long = APP_CONFIG.longitude

    server = "http://earthquake.usgs.gov/fdsnws/event/1/query"

    time_window = datetime.utcnow() - timedelta(minutes=10)

    query = {
        "format": "geojson",
        "starttime": time_window.isoformat(),
        "latitude": geo_lat,
        "longitude": geo_long,
        "maxradiuskm": 500
    }

    print("Calling USGS service.")
    response = get_http(server, params=query)
    response.raise_for_status()
    data = response.json()
    event_count = len(data["features"])
    return True if event_count > 0 else False
    
Beispiel #3
0
    def perform_request():
        """
        Perform HTTP request.
        """

        if method == "GET":
            response = get_http(server, headers=headers, json=payload)
        else:
            response = put_http(server, headers=headers, json=payload)
        response.raise_for_status()

        print("Saved to data store.")
Beispiel #4
0
def get_weather():
    """
    Get weather data from Weather Underground.
    """

    if not WEATHER_CONFIG:
        return

    url = "http://api.wunderground.com/api/{0}/conditions/q/CA/{1}.json".format(
        WEATHER_CONFIG.api_key, WEATHER_CONFIG.location)

    response = get_http(url)
    response.raise_for_status()
    data = response.json()
    conditions = data["current_observation"]["weather"]

    return conditions.encode("ascii", "ignore")
def get_weather():

    """
    Get weather data from Weather Underground.
    """

    if not WEATHER_CONFIG:
        return


    url = "http://api.wunderground.com/api/{0}/conditions/q/CA/{1}.json".format(
        WEATHER_CONFIG.api_key,
        WEATHER_CONFIG.location
    )

    response = get_http(url)
    response.raise_for_status()
    data = response.json()
    conditions = data["current_observation"]["weather"]

    return conditions.encode("ascii", "ignore")
    def perform_request():

        """
        Perform HTTP request.
        """

        if method == "GET":
            response = get_http(
                server,
                headers=headers,
                json=payload
            )
        else:
            response = put_http(
                server,
                headers=headers,
                json=payload
            )
        response.raise_for_status()

        print("saved to data store")