def get_precipitation(self, search_item, csv=False, output_dir=None, extra_param=None): """Retrieves environmental precipitation product data from the First Street Foundation API given a list of search_items and returns a list of Environmental Precipitation objects. Args: search_item (list/file): A First Street Foundation IDs, lat/lng pair, address, or a file of First Street Foundation IDs csv (bool): To output extracted data to a csv or not output_dir (str): The output directory to save the generated csvs extra_param (str): Extra parameter to be added to the url Returns: A list of Adaptation Detail """ # Get data from api and create objects api_datas = self.call_api(search_item, "environmental", "precipitation", "county", extra_param=extra_param) product = [EnvironmentalPrecipitation(api_data) for api_data in api_datas] if csv: csv_format.to_csv(product, "environmental", "precipitation", "county", output_dir=output_dir) logging.info("Environmental Precipitation Data Ready.") return product
def get_event(self, search_item, csv=False, connection_limit=100, output_dir=None, extra_param=None): """Retrieves historic event product data from the First Street Foundation API given a list of search_items and returns a list of Historic Event objects. Args: search_item (list/file): A First Street Foundation IDs, lat/lng pair, address, or a file of First Street Foundation IDs csv (bool): To output extracted data to a csv or not connection_limit (int): max number of connections to make output_dir (str): The output directory to save the generated csvs extra_param (str): Extra parameter to be added to the url Returns: A list of Historic Event """ # Get data from api and create objects api_datas = self.call_api(search_item, "historic", "event", None, connection_limit=connection_limit, extra_param=extra_param) product = [HistoricEvent(api_data) for api_data in api_datas] if csv: csv_format.to_csv(product, "historic", "event", output_dir=output_dir) logging.info("Historic Event Data Ready.") return product
def get_count_summary(self, search_items, csv=False, output_dir=None, extra_param=None): """Retrieves probability Count-Summary product data from the First Street Foundation API given a list of search_items and returns a list of Probability Count-Summary object. Args: search_items (list/file): A First Street Foundation IDs, lat/lng pair, address, or a file of First Street Foundation IDs csv (bool): To output extracted data to a csv or not output_dir (str): The output directory to save the generated csvs extra_param (dict): Extra parameter to be added to the url Returns: A list of Probability Count-Summary """ # Get data from api and create objects api_datas = self.call_api(search_items, "probability", "count-summary", "property", extra_param=extra_param) product = [ProbabilityCountSummary(api_data) for api_data in api_datas] if csv: csv_format.to_csv(product, "probability", "count-summary", output_dir=output_dir) logging.info("Probability Count-Summary Data Ready.") return product
def get_summary(self, search_item, location_type, csv=False, output_dir=None, extra_param=None): """Retrieves historic summary product data from the First Street Foundation API given a list of search_items and returns a list of Historic Summary objects. Args: search_item (list/file): A First Street Foundation IDs, lat/lng pair, address, or a file of First Street Foundation IDs location_type (str): The location lookup type csv (bool): To output extracted data to a csv or not output_dir (str): The output directory to save the generated csvs extra_param (str): Extra parameter to be added to the url Returns: A list of Historic Summary Raises: InvalidArgument: The location provided is empty TypeError: The location provided is not a string """ if not location_type: raise InvalidArgument(location_type) elif not isinstance(location_type, str): raise TypeError("location is not a string") # Get data from api and create objects api_datas = self.call_api(search_item, "historic", "summary", location_type, extra_param=extra_param) product = [HistoricSummary(api_data) for api_data in api_datas] if csv: csv_format.to_csv(product, "historic", "summary", location_type, output_dir=output_dir) logging.info("Historic Summary Data Ready.") return product
def get_detail(self, search_item, location_type, csv=False, output_dir=None, extra_param=None): """Retrieves location detail product data from the First Street Foundation API given a list of search_items and returns a list of Location Detail objects. Args: search_item (list/file): A First Street Foundation IDs, lat/lng pair, address, or a file of First Street Foundation IDs location_type (str): The location lookup type csv (bool): To output extracted data to a csv or not output_dir (str): The output directory to save the generated csvs extra_param (str): Extra parameter to be added to the url Returns: A list of Location Detail Raises: InvalidArgument: The location provided is empty TypeError: The location provided is not a string """ if not location_type: raise InvalidArgument("No loocation type provided: {}".format(location_type)) elif not isinstance(location_type, str): raise TypeError("location is not a string") # Get data from api and create objects api_datas = self.call_api(search_item, "location", "detail", location_type, extra_param=extra_param) if location_type == 'property': product = [LocationDetailProperty(api_data) for api_data in api_datas] elif location_type == 'neighborhood': product = [LocationDetailNeighborhood(api_data) for api_data in api_datas] elif location_type == 'city': product = [LocationDetailCity(api_data) for api_data in api_datas] elif location_type == 'zcta': product = [LocationDetailZcta(api_data) for api_data in api_datas] elif location_type == 'tract': product = [LocationDetailTract(api_data) for api_data in api_datas] elif location_type == 'county': product = [LocationDetailCounty(api_data) for api_data in api_datas] elif location_type == 'cd': product = [LocationDetailCd(api_data) for api_data in api_datas] elif location_type == 'state': product = [LocationDetailState(api_data) for api_data in api_datas] else: raise NotImplementedError if csv: csv_format.to_csv(product, "location", "detail", location_type, output_dir=output_dir) logging.info("Location Detail Data Ready.") return product
def get_provider(self, search_items, csv=False, output_dir=None, extra_param=None): """Retrieves AVM provider product data from the First Street Foundation API given a list of search_items and returns a list of AVM provider objects. Args: search_items (list/file): A First Street Foundation IDs, lat/lng pair, address, or a file of First Street Foundation IDs csv (bool): To output extracted data to a csv or not output_dir (str): The output directory to save the generated csvs extra_param (dict): Extra parameter to be added to the url Returns: A list of AVM Provider """ # Get data from api and create objects api_datas = self.call_api(search_items, "economic/avm", "provider", extra_param=extra_param) product = [AVMProvider(api_data) for api_data in api_datas] if csv: csv_format.to_csv(product, "economic_avm", "provider", output_dir=output_dir) logging.info("AVM Provider Data Ready.") return product
def get_summary(self, search_items, location_type, csv=False, output_dir=None, extra_param=None): """Retrieves AAL summary product data from the First Street Foundation API given a list of search_items and returns a list of AAL Summary objects. Args: search_items (list/file): A First Street Foundation IDs, lat/lng pair, address, or a file of First Street Foundation IDs location_type (str): The location lookup type csv (bool): To output extracted data to a csv or not output_dir (str): The output directory to save the generated csvs extra_param (dict): Extra parameter to be added to the url Returns: A list of AAL Summary Raises: InvalidArgument: The location provided is empty TypeError: The location provided is not a string """ if not location_type: raise InvalidArgument(location_type) elif not isinstance(location_type, str): raise TypeError("location is not a string") # Get data from api and create objects if extra_param and "depths" in extra_param: extra_param["depths"] = ','.join(map(str, extra_param["depths"])) api_datas = self.call_api(search_items, "economic/aal", "summary", location_type, extra_param=extra_param) product = [] for api_data, fsid in api_datas: api_data["fsid"] = fsid if location_type == "property": product.append(AALSummaryProperty(api_data)) else: product.append(AALSummaryOther(api_data)) if csv: csv_format.to_csv(product, "economic_aal", "summary", location_type, output_dir=output_dir) logging.info("AAL Summary Data Ready.") return product
def get_events_by_location(self, search_item, location_type, csv=False, connection_limit=100, output_dir=None, extra_param=None): """Retrieves historic summary product data from the First Street Foundation API given a list of location search_items and returns a list of Historic Summary objects. Args: search_item (list/file): A First Street Foundation IDs, lat/lng pair, address, or a file of First Street Foundation IDs location_type (str): The location lookup type csv (bool): To output extracted data to a csv or not connection_limit (int): max number of connections to make output_dir (str): The output directory to save the generated csvs extra_param (str): Extra parameter to be added to the url Returns: A list of Historic Event Raises: InvalidArgument: The location provided is empty TypeError: The location provided is not a string """ if not location_type: raise InvalidArgument(location_type) elif not isinstance(location_type, str): raise TypeError("location is not a string") # Get data from api and create objects api_datas = self.call_api(search_item, "historic", "summary", location_type, connection_limit=connection_limit) summary = [HistoricSummary(api_data) for api_data in api_datas] search_item = list(set([event.get("eventId") for sum_hist in summary if sum_hist.historic for event in sum_hist.historic])) if search_item: api_datas_event = self.call_api(search_item, "historic", "event", None, connection_limit=connection_limit, extra_param=extra_param) else: api_datas_event = [{"eventId": None}] event = [HistoricEvent(api_data) for api_data in api_datas_event] if csv: csv_format.to_csv([summary, event], "historic", "summary_event", location_type, output_dir=output_dir) logging.info("Historic Summary Event Data Ready.") return [summary, event]
def get_details_by_location(self, search_item, location_type, csv=False, output_dir=None, extra_param=None): """Retrieves adaptation detail product data from the First Street Foundation API given a list of location search_items and returns a list of Adaptation Detail objects. Args: search_item (list/file): A First Street Foundation IDs, lat/lng pair, address, or a file of First Street Foundation IDs location_type (str): The location lookup type csv (bool): To output extracted data to a csv or not output_dir (str): The output directory to save the generated csvs extra_param (str): Extra parameter to be added to the url Returns: A list of list of Adaptation Summary and Adaptation Detail Raises: InvalidArgument: The location provided is empty TypeError: The location provided is not a string """ if not location_type: raise InvalidArgument(location_type) elif not isinstance(location_type, str): raise TypeError("location is not a string") # Get data from api and create objects api_datas_summary = self.call_api(search_item, "adaptation", "summary", location_type, extra_param=extra_param) summary = [AdaptationSummary(api_data) for api_data in api_datas_summary] search_items = list(set([adaptation for sum_adap in summary if sum_adap.adaptation for adaptation in sum_adap.adaptation])) if search_items: api_datas_detail = self.call_api(search_items, "adaptation", "detail", None, extra_param=extra_param) else: api_datas_detail = [{"adaptationId": None, "valid_id": False}] detail = [AdaptationDetail(api_data) for api_data in api_datas_detail] if csv: csv_format.to_csv([summary, detail], "adaptation", "summary_detail", location_type, output_dir=output_dir) logging.info("Adaptation Summary Detail Data Ready.") return [summary, detail]
def get_count(self, search_item, location_type, csv=False, connection_limit=100, output_dir=None, extra_param=None): """Retrieves probability count product data from the First Street Foundation API given a list of search_items and returns a list of Probability Count objects. Args: search_item (list/file): A First Street Foundation IDs, lat/lng pair, address, or a file of First Street Foundation IDs location_type (str): The location lookup type csv (bool): To output extracted data to a csv or not connection_limit (int): max number of connections to make output_dir (str): The output directory to save the generated csvs extra_param (str): Extra parameter to be added to the url Returns: A list of Probability Count Raises: InvalidArgument: The location provided is empty TypeError: The location provided is not a string """ if not location_type: raise InvalidArgument(location_type) elif not isinstance(location_type, str): raise TypeError("location is not a string") # Get data from api and create objects api_datas = self.call_api(search_item, "probability", "count", location_type, connection_limit=connection_limit, extra_param=extra_param) product = [ProbabilityCount(api_data) for api_data in api_datas] if csv: csv_format.to_csv(product, "probability", "count", location_type, output_dir=output_dir) logging.info("Probability Count Data Ready.") return product