-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGetWeather.php
More file actions
59 lines (42 loc) · 1.15 KB
/
Copy pathGetWeather.php
File metadata and controls
59 lines (42 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
use WeatherAPI\Logger;
use WeatherAPI\WeatherAPI;
use WeatherAPI\PDOSource;
/*
* Load Config
* Remember to edit weather.ini to suit your environment
* Use docs/weatherdata.sql to create a database
*/
require 'config.php';
$config = parse_ini_file(CONFIG_FILE);
if ($config['devmode']) {
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
}
/*
* Create an instance of WeatherAPI and Logger
*
*/
$weather = new WeatherAPI(new PDOSource($config));
$logger = new Logger(ROOT_DIR . $config['logfile']);
if (!isset($_SERVER["HTTP_HOST"])) {
parse_str($argv[1], $_GET);
parse_str($argv[1], $_POST);
}
$location = $_POST['location'];
$weatherData = [];
if($location){
$weatherData = $weather->getLatestWeather($location);
getTemperatureFromWeatherForLocation($weatherData);
}
function getTemperatureFromWeatherForLocation($weatherData)
{
foreach ($weatherData as $wd) {
foreach ($wd as $key => $value) {
if ($key === "Temperature" || $key === "TA_PT1H_AVG") {
echo $wd['timestamp'] . " : " . $value . " c \n";
}
}
}
}