def sorted_spot_based_on_distance(self): """ Call Google API service first to obtain lat and lng data Then call spitcast with lat and lng data from google api service return a dict with the following formate { status: <either "thumbsup" or "thumbsdown"> error: [list of errors] data: [spit cast response data] } """ self.__google_location_api_call() self.__nearby_surf_spots() resulting_response = {"status": "thumbsup", "error": self.error, "data": self.response_data} if len(self.error) > 0: resulting_response["status"] = "thumbsdown" else: # Loop through the response data and estimating the distance between surf spot and current location # Add distance data to response_data object for item in self.response_data: lng2, lat2 = item["coordinates"] distance_from_location = haversine(float(self.lng), float(self.lat), float(lng2), float(lat2)) item["distance_from_location"] = distance_from_location # sort the distance data in response_data object from closest to the farest resulting_response["data"] = sort_list_with_dictionary_data( self.response_data, "distance_from_location", False ) return resulting_response
def sorted_top_spot_swell_data(self): ''' Call spit cast api to get a list of top swell spots. sort the response data then return a dict with the following formate { status: <either "thumbsup" or "thumbsdown"> error: [list of errors] data: [spit cast response data] } ''' # TODO: Query the data first before making an API Call. Need to add db utility methods self.__top_spot_swell_spots() self.response_data = sort_list_with_dictionary_data(self.response_data, "avg_max_size") resulting_response = {"status":"thumbsup", "error":self.error, "data":self.response_data} if len(self.error) > 0: resulting_response['status'] = "thumbsdown" return resulting_response