Example #1
0
    def __init__(self, zoneID, user_agent):

        self._validate(zoneID)  # make sure the data is valid.

        if isinstance(zoneID, str):
            zoneID = [
                zoneID
            ]  # make it a list, eliminates unnecessary if/else statements.

        self.alerts = []
        self.response_headers = []
        ac = AlertConstructor()
        for zone in zoneID:
            zone = zone.upper()
            response = utils.request(
                f"https://api.weather.gov/alerts/active/zone/{zone}",
                headers=user_agent)
            if not isinstance(response, requests.models.Response):
                self.alerts.append(response)
                continue

            info = response.json()['features']
            for x in info:
                self.alerts.append(ac.construct_alert(x))
            self.response_headers.append(response.headers)

        self._counter = collections.Counter(
            x.event for x in self.alerts)  # counts the number of alerts
Example #2
0
    def __init__(self, alert_id, user_agent):

        self._validate(alert_id)
        if isinstance(alert_id, str):
            alert_id = [
                alert_id
            ]  # this is only to make it consistent with logic below.

        self.alerts = []
        self.response_headers = []
        ac = AlertConstructor()
        for a_id in alert_id:  # iterate through the alerts
            response = utils.request(f"https://api.weather.gov/alerts/{a_id}",
                                     user_agent)
            if not isinstance(response, requests.models.Response):
                self.alerts.append(
                    response
                )  # if something weird went wrong, put an error response in.
                continue

            info = response.json()  # all is good, construct the alert objects.
            self.alerts.append(ac.construct_alert(info))
            self.response_headers.append(response.headers)

        self._counter = collections.Counter(
            x.event for x in self.alerts)  # counts the number of alerts
Example #3
0
    def __init__(self, user_agent):
        response = utils.request("https://api.weather.gov/alerts/types",
                                 headers=user_agent)
        if isinstance(response,
                      requests.models.Response):  # successful retrieval.
            self.alerts = response.json()['eventTypes']
        else:
            self.alerts = [response]

        self.response_headers = response.headers
Example #4
0
    def __init__(self, user_agent):
        response = utils.request("https://api.weather.gov/alerts",
                                 headers=user_agent)

        if isinstance(response,
                      requests.models.Response):  # successful retrieval
            info = response.json()['features']
            ac = AlertConstructor()
            self.alerts = [ac.construct_alert(x) for x in info]
        else:
            self.alerts = [response]

        self._counter = collections.Counter(x.event for x in self.alerts)
        self.response_headers = response.headers
Example #5
0
    def __init__(self, user_agent):
        response = utils.request("https://api.weather.gov/alerts/active/count",
                                 headers=user_agent)
        self.response_headers = response.headers

        if isinstance(response, requests.models.Response):
            info = response.json()
            self.total = info['total']  # dtype: int
            self.land = info['land']  # dtype: int
            self.marine = info['marine']  # dtype: int
            self.regions = info['regions']  # dtype: dict {str : int}
            self.areas = info['areas']  # dtype: dict {str : int}
            self.zones = info['zones']  # dtype: dict {str : int}
        else:
            self.alerts = [response]
Example #6
0
    def __init__(self, user_agent):

        # Update for 0.2.0: allow users to input values to modify the URL. Lots of checking!

        # active = boolean
        # start_time = datetime object TO 2021-05-19T10:45:00-05:00 (https://en.m.wikipedia.org/wiki/ISO_8601#Durations)
        # end_time = datetime object TO ISO duration (above)
        # status = string [actual, exercise, system, test, draft]
        # message_type = string [alert, update, cancel]
        # event = string [Valid NWS alert products, see table]
        # code = string (no clue what this is)
        # region_type = string [land or marine], This parameter is incompatible with the following parameters:
        #       area, point, region, zone
        # point = string (NOTE: must be 38,-99 WATCH SPACES!, truncate to 4 decimal places).
        #       maybe make a shapely point? OR could create a NWSAPy point. This parameter is incompatible with the
        #       following parameters: area, region, region_type, zone
        # region = string [Valid marine regions, see table] This parameter is incompatible with the following
        #       parameters: area, point, region_type, zone
        # area = string [Valid areas, see table] This parameter is incompatible with the following parameters:
        #       point, region, region_type, zone
        # zone = string [Don't have a table for this, but something like ABC001] This parameter is incompatible with
        #       the following parameters: area, point, region, region_type
        # urgency = string  [immediate, expected, future, past, unknown]
        # severity = string [extreme, severe, moderate, minor, unknown]
        # certainty = string [observed, likely, possible, unlikely, unknown]
        # limit = integer (how many alerts you want, 0 to ??, look into capping it?)
        # cursor = what is this I don't even know

        response = utils.request("https://api.weather.gov/alerts/active",
                                 user_agent)

        if isinstance(response, requests.models.Response):
            info = response.json()['features']
            ac = AlertConstructor()
            self.alerts = [ac.construct_alert(x) for x in info
                           ]  # opted for list comp because it's faster
        else:
            self.alerts = [response]
        self._counter = collections.Counter(
            x.event for x in self.alerts)  # counts the number of alerts
        self.response_headers = response.headers  # requests.structures.CaseInsensitiveDict
Example #7
0
    def __init__(self, user_agent):

        response = utils.request("https://api.weather.gov/",
                                 headers=user_agent)
        self.status = response.json()['status']
        self.response_headers = response.headers