This project is not covered by Drupal’s security advisory policy.

This module is NOT an official one and uses AEMET, Agencia Estatal de Metereología, data from their OpenData API.

Sky icons get from weather_es module.

This enables the AEMET PHP API and a simple block to show weather information.

API call example in aemet/src/Plugin/Block/SimpleAemetWeatherBlock::build()

/**
   * {@inheritdoc}
   */
  public function build() {
    try {
      // Module configuration.
      $modSettings = $this->configFactory->get('aemet.settings');

      // Prepare AEMET API configuration.
      $aemetCfg = new Configuration();
      $aemetCfg->setApiKey('api_key', $modSettings->get('api_key'));

      // Call authorization endpoint.
      $pred = new PrediccionesEspecificasApi(NULL, $aemetCfg);
      $mod200 = $pred->prediccinPorMunicipiosDiariaTiempoActual_($this->configuration['city']);
      // Call authorized endpoint to get real data.
      // @see $this->aemetValues->getFinalMetaData($mod200); response to
      // get help.
      $data = $this->aemetValues->getFinalData($mod200);
      // @todo: Build block.
      $build['content'] = [
        '#markup' => $this->t('It works!'),
      ];
    }
    catch (\Exception $e) {
      $build = [];
      $this->logger->alert($this->t('Remote call error "@message" in line @line of @file: @trace', [
        '@message' => $e->getMessage(),
        '@file' => $e->getFile(),
        '@line' => $e->getLine(),
        '@trace' => $e->getTraceAsString(),
      ]));
    }

    return $build;
  }

The simple block allow alter her city:

/**
 * Allow alter the configured city to show.
 *
 * @param string $cityToShow
 *   The actual city code.
 */
function hook_aemet_block_city_alter(&$cityToShow) {
  // Show Almonte weather.
  // The code is the province ID, 21 to Huelva,
  // and de city code, 005 to Almonte.
  $cityToShow = '21005';
}
Supporting organizations: 

Project information

Releases