PHP code example of ajur-media / ajur.weather

1. Go to this page and download the library: Download ajur-media/ajur.weather library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ajur-media / ajur.weather example snippets


/**
 * @param int $district_id
 * @param null $source_file
 * @return array
 */
public static function loadLocalWeather($district_id = 0, $source_file = null)

/**
 * Загружает из OpenWeather погоду для переданного массива регионов
 *
 * @param array $regions_list - либо список регионов (многомерный массив), либо список ключей регионов (array_keys)
 * @return array
 * @throws OpenWeatherMap\Exception
 */
public static function fetchWeatherGroup(array $regions_list):array

/**
 * @param array $regions_list
 * @return array
 * @throws OpenWeatherMap\Exception
 */
public static function fetchWeatherGroupDebug(array $regions_list): array



use AJUR\Toolkit\Weather;

Weather::init('<api key>');

$data = Weather::fetchWeatherGroup( array_keys( \AJUR\Toolkit\WeatherConstants::outer_regions ) );

$data = [
    'update_ts'     =>  time(),
    'update_time'   =>  (new \DateTime())->format('Y-m-d H-i-s'),
    'data'          =>  $data
];

file_put_contents('weather.json', json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE  ), LOCK_EX);