Files
EQN/appServer/test_weather.php
2017-09-22 15:16:26 +02:00

38 lines
1.1 KiB
PHP

<?php
$ini = parse_ini_file("conf.ini", true);
mysql_connect($ini['db']['host'],$ini['db']['user'],$ini['db']['pass']);
mysql_select_db($ini['db']['db']);
if ($ini['db']['log']=="1"){
$arrival_time=microtime(true);
$filename=basename(__FILE__);
$filename="log_".$filename.".txt";
$chunck=strval($arrival_time)." ".$_SERVER['REQUEST_URI']."\r\n";
file_put_contents($filename,$chunck,FILE_APPEND);
}
mysql_set_charset("utf8");
$url="http://api.openweathermap.org/data/2.5/weather?lat=45.575&lon=9.536&lang=it&lang=es&appid=2de02dac92c8a20f8571feb5ad5bdcaa";
$json = file_get_contents($url);
$data = json_decode($json, TRUE);
$weather_code=$data["weather"][0]["id"];
$icon=$data["weather"][0]["icon"];
$temperature=$data["main"]["temp"];
$pressure=$data["main"]["pressure"];
$humidity=$data["main"]["humidity"];
$wind_speed=$data["wind"]["speed"];
$wind_direction=$data["wind"]["deg"];
$clouds_coverage=$data["clouds"]["all"];
$temp=$data["weather"][0]["id"];
if (!is_null($temp))
{
print('ok!');
}
mysql_close();
?>