Пример #1
0
def consult_lag(locality_id, conn=None):
    '''

    '''
    params = {'locality_id': locality_id}

    query = """
        SELECT 
            lag 
        FROM weather_forecasting_day
        WHERE
            locality_id = :locality_id
    """
    if conn:
        try:
            MYSQL.session_execute(
                query=query,
                params=params,
                connection=conn,
            )
        except:
            return False
    else:
        try:
            MYSQL.execute(query=query, params=params)
        except:
            return False

    if MYSQL.result:
        return MYSQL.result
Пример #2
0
def exist_wfday(locality_id, date, conn=None):
    '''

    '''
    params = {'locality_id': locality_id, 'date': date}

    query = """
        SELECT * 
        FROM weather_forecasting_day
        WHERE
            locality_id = :locality_id
            AND date = :date;
    """
    if conn:
        try:
            MYSQL.session_execute(
                query=query,
                params=params,
                connection=conn,
            )
        except:
            return False
    else:
        try:
            MYSQL.execute(query=query, params=params)
        except:
            return False

    if MYSQL.result:
        return True

    return True
Пример #3
0
def update_wfday(parameters, conn=None):
    '''

    '''
    params = {
        'id': parameters['id'],
        'locality_id': parameters['locality_id'],
        'precipitation': parameters['precipitation'],
        'weather': parameters['weather'],
        '_date': parameters['date'],
        '_max': parameters['max'],
        '_min': parameters['min'],
        'lag': parameters['lag'],
    }
    query = 'UPDATE `weather_forecasting_day` SET weather = :weather, \
            precipitation = :precipitation, \
            `max` = :_max, \
            `min` = :_min, \
            `date` = :_date, \
            locality_id = :locality_id, \
            lag = :lag \
            WHERE id = :id'

    if conn:
        try:
            MYSQL.session_execute(query=query,
                                  params=params,
                                  connection=conn,
                                  get_results=False,
                                  check_for_empty_result=False)
        except:
            logger.exception(
                "error to update weather forecasting: [{}]".format(parameters))
            return False
    else:
        try:
            MYSQL.execute(query=query,
                          params=params,
                          get_results=False,
                          check_for_empty_result=False)
        except:
            logger.exception(
                "error to update weather forecasting: [{}]".format(parameters))
            return False

    logger.info('weather forecasting day updated with successfully!')
    return True
Пример #4
0
def consult_wfday(locality_id, date, conn=None):
    '''

    '''
    params = {'locality_id': locality_id, 'date': date}

    query = """
        SELECT * 
        FROM weather_forecasting_day
        WHERE
            locality_id = :locality_id
            AND date = :date;
    """
    if conn:
        try:
            MYSQL.session_execute(
                query=query,
                params=params,
                connection=conn,
            )
        except:
            return False
    else:
        try:
            MYSQL.execute(query=query, params=params)
        except:
            return False

    if MYSQL.result:
        return {
            'id': MYSQL.result[0]['id'],
            'weather': MYSQL.result[0]['weather'],
            'precipitation': MYSQL.result[0]['precipitation'],
            'date': MYSQL.result[0]['date'],
            'max': MYSQL.result[0]['max'],
            'min': MYSQL.result[0]['min'],
            'locality_id': MYSQL.result[0]['locality_id'],
            'lag': MYSQL.result[0]['lag']
        }
Пример #5
0
def create_wfday(parameters, conn=None):
    '''

    '''
    params = {
        'locality_id': parameters['locality_id'],
        'precipitation': parameters['precipitation'],
        'weather': parameters['weather'],
        'date': parameters['date'],
        'max': parameters['max'],
        'min': parameters['min'],
        'lag': parameters['lag'],
    }

    if exist_wfday(params['locality_id'], params['date'], conn):
        return True

    query = """
        INSERT INTO `weather_forecasting_day`(
            weather,
            precipitation,
            `date`,
            `max`,
            `min`,
            locality_id,
            lag

        )
	    VALUES(
            :weather,
            :precipitation,
            :date,
            :max,
            :min,
            :locality_id,
            :lag
        );
    """
    if conn:
        try:
            MYSQL.session_execute(query=query,
                                  params=params,
                                  connection=conn,
                                  get_results=False,
                                  check_for_empty_result=False)
        except:
            logger.exception(
                "error to create weather forecasting: [{}]".format(parameters))
            return False
    else:
        try:
            MYSQL.execute(query=query,
                          params=params,
                          get_results=False,
                          check_for_empty_result=False)
        except:
            logger.exception(
                "error to create weather forecasting: [{}]".format(parameters))
            return False

    logger.info('weather forecasting day created with successfully!')
    return True
Пример #6
0
def create_wfhour(parameters, conn=None):
    '''

    '''
    params = {
        'locality_id': parameters['locality_id'],
        'temp': parameters['temp'],
        'weather': parameters['weather'],
        'last_update': parameters['last_update'],
        'wind': parameters['wind'],
        'atmospheric_pressure': parameters['atmospheric_pressure'],
        'relative_humidity': parameters['relative_humidity'],
        'date_time': parameters['date_time']
    }

    if exist_wfhour(params['locality_id'], params['date_time'], conn):
        logger.info(
            'weather forecasting hour alread exist: [{0}] '.format(parameters))
        return True

    query = """
        INSERT INTO `weather_forecasting_hour`(
                atmospheric_pressure,
                wind,
                temp,
                relative_humidity,
                last_update,
                weather,
                locality_id,
                date_time
            )
	    VALUES(
            :atmospheric_pressure,
            :wind,
            :temp,
            :relative_humidity,
            :last_update,
            :weather,
            :locality_id,
            :date_time
            );
    """
    if conn:
        try:
            MYSQL.session_execute(query=query,
                                  params=params,
                                  connection=conn,
                                  get_results=False,
                                  check_for_empty_result=False)
        except:
            logger.exception(
                "error to create weather forecasting: [{}]".format(parameters))
            return False
    else:
        try:
            MYSQL.execute(query=query,
                          params=params,
                          get_results=False,
                          check_for_empty_result=False)
        except:
            logger.exception(
                "error to create weather forecasting: [{}]".format(parameters))
            return False

    logger.info('weather forecasting hour created with successfully!')
    return True