8 /******************************
10 *******************************
11 * 0.1 -> Initial Release *
12 * 0.2 -> Config options *
13 * 0.3 -> Day and Night *
14 * 0.4 -> Fancy Canvas Version *
15 *******************************/
18 /*Weather.com configuration
19 ********************************/
20 $citycode = 'MXCA0026'; //Zip Code (US) or City code according to weather.com
21 $partnerid = '1140062701'; //Partner ID
22 $license = '5b323d77586070aa'; //License number
25 ********************************/
26 $nightbackground = '#21272A'; //main colors.
27 $daybackground = '#99cce1';
29 $coldcolor = 'rgb(120,214,253)'; //Colors for each temperature.
30 $coolcolor = 'rgb(27,149,251)';
31 $temperatecolor = 'rgb(153,153,153)';
32 $warmcolor = 'rgb(255,146,38)';
33 $hotcolor = 'rgb(255,24,24)';
36 *******************************/
37 $coldstring = 'frío.'; //string for each temperature.
38 $coolstring = 'fresco.';
39 $regularstring = 'regular.';
40 $warmstring = 'cálido.';
41 $hotstring = 'caliente.';
43 $coldtagline = '(abrigate bien.)'; //tagline for each temperature.
44 $cooltagline = '(perfecto para un saco.)';
45 $regulartagline = '(ni fu ni fa.)';
46 $warmtagline = '(como para estar afuera.)';
47 $hottagline = '(hidrátate bien.)';
49 /*Temperature Configuration
50 ******************************/
51 $coldlimit = 15; //How many degrees? (celsius)
58 /******************************
60 *******************************
61 * Don't edit below this part *
62 * unless you know what you're *
64 *******************************
65 * It's not that hard really. *
66 * but it's better if we leave *
67 * it like it is. Unless you *
68 * like customizing the shit *
70 *******************************/
73 $ch = curl_init('http://xoap.weather.com/weather/local/'.$citycode.'?cc=*&link=xoap&prod=xoap&par='.$partnerid.'&key='.$license.''); //Initialize curl.
75 curl_setopt($ch, CURLOPT_RETURNTRANSFER
, true); //More curl config
76 curl_setopt($ch, CURLOPT_CONNECTTIMEOUT
, 4);
78 $data = curl_exec($ch); //this is your xml stuff
81 $xml = new SimpleXmlElement($data, LIBXML_NOCDATA
); //now let's make an XmlElement
82 $feelslike = $xml->cc
->flik
; //This is the "Feel's Like temp"
83 $sunset = date('G.i',strtotime($xml->loc
->suns
));
84 $sunrise = date('G.i',strtotime($xml->loc
->sunr
));
85 $now = date('G.i',time()-28800);
86 switch($xml->cc
->icon
){
87 case 0: case 1: case 2: case 3:
88 case 4: case 5: case 6: case 7:
89 case 8: case 9: case 10: case 11:
90 case 12: case 13: case 14: case 15:
91 case 16: case 17: case 18: case 35:
92 case 37: case 38: case 39: case 40:
93 case 41: case 42: case 43: case 44:
94 case 45: case 46: case 47:
97 case 19: case 20: case 21: case 22:
98 case 23: case 24: case 25: case 26:
99 case 27: case 28: case 29: case 30:
106 $feelslike = ($feelslike -32)*5/9; //Convert fahrenheit to celsius.
108 //now let's get the sponsored links. Stupid EULA.
109 $sponsors = '<a href="'.$xml->lnks
->link
[0]->l
.'">'.$xml->lnks
->link
[0]->t
.'</a> · ';
110 $sponsors .= '<a href="'.$xml->lnks
->link
[1]->l
.'">'.$xml->lnks
->link
[1]->t
.'</a> · ';
111 $sponsors .= '<a href="'.$xml->lnks
->link
[2]->l
.'">'.$xml->lnks
->link
[2]->t
.'</a> · ';
112 $sponsors .= '<a href="'.$xml->lnks
->link
[3]->l
.'">'.$xml->lnks
->link
[3]->t
.'</a>';
115 if(isset($_GET['temp'])){
116 $feelslike = $_GET['temp']; //This overrides the weather.com temperature for debugging.
118 if(isset($_GET['now'])){
119 $now = $_GET['now']; //This overrides the weather.com date for debugging.
121 if(isset($_GET['sky'])){ //This overrides the weather.com sky conditions for debugging.
126 echo '<?xml version="1.0" encoding="UTF-8"?>
127 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
128 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">';
131 <!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
132 <html xmlns
="http://www.w3.org/1999/xhtml" xml
:lang
="en">
134 <meta http
-equiv
="Content-Type" content
="text/html; charset=utf-8" />
135 <title
>¿Cómo está el clima en Juárez
?</title
>
136 <style type
="text/css">
143 font
-family
: "Helvetica Neue", Helvetica
, Arial
, sans
-serif
;
146 if($now > $sunrise && $now < $sunset){
147 echo 'background-color:'.$daybackground.';';
149 echo 'background-color:'.$nightbackground.';';
168 <script type
="text/javascript">
170 var canvas
= document
.getElementById('theCanvas');
171 var context
= canvas
.getContext('2d');
175 gradient
= context
.createLinearGradient(0, 600, 0, 300);
176 gradient
.addColorStop(0, "rgb(255,255,255)");
177 gradient
.addColorStop(1, "rgb(240,240,240)");
179 context
.fillStyle
= gradient
;
181 context
.moveTo(10,600);
182 context
.lineTo(10,535);
183 context
.lineTo(110,535);
184 context
.lineTo(110,550);
185 context
.lineTo(250,550);
186 context
.lineTo(250,500);
187 context
.lineTo(270,510);
188 context
.lineTo(270,500);
189 context
.lineTo(290,510);
190 context
.lineTo(290,500);
191 context
.lineTo(310,510);
192 context
.lineTo(310,500);
193 context
.lineTo(330,510);
194 context
.lineTo(330,450);
195 context
.lineTo(340,450);
196 context
.lineTo(340,510);
197 context
.lineTo(350,510);
198 context
.lineTo(350,470);
199 context
.lineTo(360,470);
200 context
.lineTo(360,510);
201 context
.lineTo(400,510);
202 context
.lineTo(400,340);
203 context
.lineTo(420,320);
204 context
.lineTo(440,320);
205 context
.lineTo(480,300);
206 context
.lineTo(520,320);
207 context
.lineTo(540,320);
208 context
.lineTo(560,340);
209 context
.lineTo(560,550);
210 context
.lineTo(600,550);
211 context
.lineTo(600,575);
212 context
.lineTo(625,560);
213 context
.lineTo(650,575);
214 context
.lineTo(675,560);
215 context
.lineTo(700,575);
216 context
.lineTo(725,560);
217 context
.lineTo(750,575);
218 context
.lineTo(775,560);
219 context
.lineTo(800,575);
220 context
.lineTo(800,500);
221 context
.lineTo(950,500);
222 context
.lineTo(950,600);
226 context
.strokeStyle
= "rgb(96,96,96)";
228 context
.moveTo(0,600);
229 context
.lineTo(960,600);
234 if($feelslike < $coldlimit){
235 echo 'var tempText = "'.$coldstring.'";'."\n";
236 echo 'var tempColor = "'.$coldcolor.'";'."\n";
237 }else if($feelslike < $coollimit){
238 echo 'var tempText = "'.$coolstring.'";'."\n";
239 echo 'var tempColor = "'.$coolcolor.'";'."\n";
240 }else if($feelslike < $temperatelimit){
241 echo 'var tempText = "'.$regularstring.'";'."\n";
242 echo 'var tempColor = "'.$regularcolor.'";'."\n";
243 }else if($feelslike < $warmlimit){
244 echo 'var tempText = "'.$warmstring.'";'."\n";
245 echo 'var tempColor = "'.$warmcolor.'";'."\n";
247 echo 'var tempText = "'.$hotstring.'";'."\n";
248 echo 'var tempColor = "'.$hotcolor.'";'."\n";
253 drawTemperature(context
,tempText
,tempColor
);
259 echo "drawSun(context);\n drawCloud(context);\n";
262 echo "drawSun(context);\n drawCloud(context);\n drawRain(context);\n";
265 echo "drawSun(context);\n";
273 //draws the "fuzzy" temperature.
274 function drawTemperature(context
,tempString
,tempColor
){
275 context
.font
= "10pt Helvetica";
276 context
.fillStyle
= "rgb(101,101,101)";
277 context
.fillText("Juárez está:", 15, 595);
278 context
.fillStyle
= tempColor
;
279 context
.fillText(tempString
, 92, 595);
282 //function to draw the sun.
283 function drawSun(context
){
284 context
.fillStyle
= "rgb(96,96,96)";
286 context
.arc(860,100,50,0,Math
.PI
*2,true);
290 //function to draw the rain
291 function drawRain(context
){
292 for(var i
= 0;i
<4;i++
){
293 for(var j
= 0;j
<2;j++
){
294 context
.strokeStyle
= "rgb(96,96,96)";
296 context
.moveTo(760+
(i
*40)-(j
*40),180+
(j
*40));
297 context
.lineTo(730+
(i
*40)-(j
*40),210+
(j
*40));
303 //function to draw a cloud over the sun
304 function drawCloud(context
){
305 context
.fillStyle
= "rgb(255,255,255)";
307 context
.arc(880,140,35,0,Math
.PI
*2,true);
310 context
.arc(840,130,45,0,Math
.PI
*2,true);
313 context
.arc(790,145,30,0,Math
.PI
*2,true);
316 context
.arc(800,110,35,0,Math
.PI
*2,true);
319 context
.arc(775,125,25,0,Math
.PI
*2,true);
324 <body onload
="draw();">
326 <canvas id
="theCanvas" width
="960px" height
="600px"></canvas
>