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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
<?php
$config = dirname(__FILE__)."/update_weather.config";
$ini_array = parse_ini_file($config);
$latitude = $ini_array['Latitude'];
$longitude = $ini_array['Longitude'];
$locationSkin = $ini_array['LocationSkin'];
$units = $ini_array['Units'];
$degree_sign = $ini_array['DegreeSign'];
$lang = $ini_array['Lang'];
$convertPoint = $ini_array['ConvertPoint2Comma'];
$api_key = $ini_array['ApiKey'];
$OUTPUTFLDRTEMP = "/tmp/skinflatplus/widgets/weather";
if( !file_exists($OUTPUTFLDRTEMP) )
mkdir($OUTPUTFLDRTEMP, 0775, true);
include('lib/forecast.io.php');
// delete old files
array_map('unlink', glob($OUTPUTFLDRTEMP."/weather.*"));
// forecast query
$forecast = new ForecastIO($api_key);
$condition = $forecast->getCurrentConditions($latitude, $longitude, $units, $lang);
if( !$handle = fopen($OUTPUTFLDRTEMP."/weather.0.temp", "w") ) {
print "can't create file!\n";
continue;
}
$temp = round($condition->getTemperature(), 1);
if( $convertPoint == 1 )
$temp = str_replace(".", ",", $temp);
fwrite($handle, $temp);
fwrite($handle, $degree_sign);
fclose($handle);
// get daily conditions for next 7 days
$conditions_week = $forecast->getForecastWeek($latitude, $longitude, $units, $lang);
if( !$handle = fopen($OUTPUTFLDRTEMP."/weather.location", "w") ) {
print "can't create file!\n";
} else {
fwrite($handle, $locationSkin);
fclose($handle);
}
$index = -1;
foreach($conditions_week as $conditions) {
$index++;
if( !$handle = fopen($OUTPUTFLDRTEMP."/weather.".$index.".summary", "w") ) {
print "can't create file!\n";
continue;
}
fwrite($handle, $conditions->getSummary());
fclose($handle);
if( !$handle = fopen($OUTPUTFLDRTEMP."/weather.".$index.".tempMin", "w") ) {
print "can't create file!\n";
continue;
}
// we only have min & max so we must calc
$temp = round($conditions->getMinTemperature(), 1);
if( $convertPoint == 1 )
$temp = str_replace(".", ",", $temp);
fwrite($handle, $temp);
fwrite($handle, $degree_sign);
fclose($handle);
if( !$handle = fopen($OUTPUTFLDRTEMP."/weather.".$index.".tempMax", "w") ) {
print "can't create file!\n";
continue;
}
// we only have min & max so we must calc
$temp = round($conditions->getMaxTemperature(), 1);
if( $convertPoint == 1 )
$temp = str_replace(".", ",", $temp);
fwrite($handle, $temp);
fwrite($handle, $degree_sign);
fclose($handle);
if( !$handle = fopen($OUTPUTFLDRTEMP."/weather.".$index.".precipitation", "w") ) {
print "can't create file!\n";
continue;
}
fwrite($handle, $conditions->getPrecipitationProbability());
fclose($handle);
if( !$handle = fopen($OUTPUTFLDRTEMP."/weather.".$index.".precipitationType", "w") ) {
print "can't create file!\n";
continue;
}
if( $conditions->getPrecipitationProbability() > 0 )
fwrite($handle, $conditions->getPrecipitationType());
else
fwrite($handle, "none");
fclose($handle);
if( !$handle = fopen($OUTPUTFLDRTEMP."/weather.".$index.".icon", "w") ) {
print "can't create file!\n";
continue;
}
fwrite($handle, $conditions->getIcon());
fclose($handle);
}
?>
|