OpenWeatherMap-API/weather_api_class.py
def query_preprocessing(self, query_type, query_name, parameters):
        """
        Function defined to return the desired query updated with the list of parameters.
        :param query_type: Integer value that represents the family of queries to be executed.
            0: Current weather queries
            1: 5 days forecast
            2: UV index
        :param query_name: Name of the query as it was defined in the LIST_QUERY to be executed
        :param parameters: List with the set of parameters to be included in the query
        :return: a string with the query replacing the param label with the values included in the parameter list
        """
        query = ""
        query_list_values = self.query_list(query_id=query_type)
        if "-1" in query_list_values:
            print("Not a valid list ID was entered")
            return {'error': -1}
        else:
            if query_name in query_list_values:
                list_qnr = query_list_values[query_name]
                num_param = len(re.findall("PARAM\d", list_qnr[0]))
                if num_param > len(parameters):
                    return "Number of parameters: {}, required by the query: {}. Update the list of parameters".format(len(parameters), num_param)
                query = list_qnr[0]

                # Bucle to update the list of parameters for the query
                for i in range(num_param):
                    cad = "{PARAM" + str(i + 1) + "}"
                    query = re.sub(cad, str(parameters[i]), query)

                # Bucle to add the optional set of parameters in the query
                j = 1
                for i in range(num_param, len(parameters)):
                    if j < len(list_qnr):
                        cad = "{PARAM" + str(i + 1) + "}"
                        query = query + re.sub(cad, str(parameters[i]), list_qnr[j])
                        j += 1
                return query
            else:
                print("No valid query was entered")
                return {'error': -1}

        Function defined to return the desired query updated with the list of parameters.
        :param query_type: Integer value that represents the family of queries to be executed.
            0: Current weather queries
            1: 5 days forecast
            2: UV index
        :param query_name: Name of the query as it was defined in the LIST_QUERY to be executed
        :param parameters: List with the set of parameters to be included in the query
        :return: a string with the query replacing the param label with the values included in the parameter list
        
Function defined to return the desired query updated with the list of parameters.
Function defined to return the desired query updated with the list of parameters .
def query_preprocessing(self, query_type, query_name, parameters):
        query = ""
        query_list_values = self.query_list(query_id=query_type)
        if "-1" in query_list_values:
            print("Not a valid list ID was entered")
            return {'error': -1}
        else:
            if query_name in query_list_values:
                list_qnr = query_list_values[query_name]
                num_param = len(re.findall("PARAM\d", list_qnr[0]))
                if num_param > len(parameters):
                    return "Number of parameters: {}, required by the query: {}. Update the list of parameters".format(len(parameters), num_param)
                query = list_qnr[0]
                for i in range(num_param):
                    cad = "{PARAM" + str(i + 1) + "}"
                    query = re.sub(cad, str(parameters[i]), query)
                j = 1
                for i in range(num_param, len(parameters)):
                    if j < len(list_qnr):
                        cad = "{PARAM" + str(i + 1) + "}"
                        query = query + re.sub(cad, str(parameters[i]), list_qnr[j])
                        j += 1
                return query
            else:
                print("No valid query was entered")
                return {'error': -1}
def query_preprocessing ( self , query_type , query_name , parameters ) : query = "" query_list_values = self . query_list ( query_id = query_type ) if "-1" in query_list_values : print ( "Not a valid list ID was entered" ) return { 'error' : - 1 } else : if query_name in query_list_values : list_qnr = query_list_values [ query_name ] num_param = len ( re . findall ( "PARAM\d" , list_qnr [ 0 ] ) ) if num_param > len ( parameters ) : return "Number of parameters: {}, required by the query: {}. Update the list of parameters" . format ( len ( parameters ) , num_param ) query = list_qnr [ 0 ] for i in range ( num_param ) : cad = "{PARAM" + str ( i + 1 ) + "}" query = re . sub ( cad , str ( parameters [ i ] ) , query ) j = 1 for i in range ( num_param , len ( parameters ) ) : if j < len ( list_qnr ) : cad = "{PARAM" + str ( i + 1 ) + "}" query = query + re . sub ( cad , str ( parameters [ i ] ) , list_qnr [ j ] ) j += 1 return query else : print ( "No valid query was entered" ) return { 'error' : - 1 }
Function defined to return the desired query updated with the list of parameters.
Function defined to return the desired query updated with the list of parameters .
"""
        Function defined to return the desired query updated with the list of parameters.
        :param query_type: Integer value that represents the family of queries to be executed.
            0: Current weather queries
            1: 5 days forecast
            2: UV index
        :param query_name: Name of the query as it was defined in the LIST_QUERY to be executed
        :param parameters: List with the set of parameters to be included in the query
        :return: a string with the query replacing the param label with the values included in the parameter list
        """ # Bucle to update the list of parameters for the query # Bucle to add the optional set of parameters in the query
a string with the query replacing the param label with the values included in the parameter list
a string with the query replacing the param label with the values included in the parameter list
self
query_type
Integer value that represents the family of queries to be executed.
0: Current weather queries
1: 5 days forecast
2: UV index
Integer value that represents the family of queries to be executed . 0 : Current weather queries 1 : 5 days forecast 2 : UV index
query_name
Name of the query as it was defined in the LIST_QUERY to be executed
Name of the query as it was defined in the LIST_QUERY to be executed
parameters
List with the set of parameters to be included in the query
List with the set of parameters to be included in the query