-
Notifications
You must be signed in to change notification settings - Fork 0
/
weather_json.php
59 lines (46 loc) · 1.52 KB
/
weather_json.php
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
58
59
<?php
error_reporting(0);
include('functions.php');
require_once('config.php');
global $set;
$lat = $_REQUEST['lat'];
$lon = $_REQUEST['lon'];
$timezone = get_time_zone($_REQUEST['country'],$_REQUEST['state']);
date_default_timezone_set($timezone);
$zenith = 96;
$tzoffset = date("Z")/60 / 60;
$set = day_or_night($lat,$lon,$tzoffset,$zenith);
$data = get_cached_file('http://api.wunderground.com/api/b2a9cff9e9e6dbcf/conditions/q/'.$lat.','.$lon.'.json');
$data2 = get_cached_file('http://api.wunderground.com/api/b2a9cff9e9e6dbcf/forecast/q/'.$lat.','.$lon.'.json');
$data = json_decode($data);
$data2 = json_decode($data2);
$current = $data->current_observation;
$current_json = array(
'update_time'=>date('g:i a',$current->observation_epoch),
'temperature'=>((int)$current->temp_f).'°',
'wind'=>((int)$current->wind_mph).'mph',
'weather'=>$current->weather,
'icon'=>get_icon($current->icon),
'precip'=>$data2->forecast->simpleforecast->forecastday[0]->pop.'%'
);
$forecast_array = array();
foreach($data2->forecast->simpleforecast->forecastday as $forecast)
{
$data = array(
'day'=>$forecast->date->weekday_short,
'high'=>$forecast->high->fahrenheit.'°',
'low'=>$forecast->low->fahrenheit.'°',
'icon'=>get_icon($forecast->icon,true),
'precip'=>$forecast->pop
);
array_push($forecast_array,$data);
}
$json =
json_encode(
array(
'place'=>$current->display_location->full,
'current_conditions'=>$current_json,
'forecast'=>$forecast_array
)
);
echo 'weather('.$json.');';