]> git.r.bdr.sh - rbdr/r.bdr.sh/blob - jekyll/clima2/index.php
Points to tomato sauce
[rbdr/r.bdr.sh] / jekyll / clima2 / index.php
1 <?php
2 /********************
3 * Fuzzy Thermometer *
4 * Ver 0.3 *
5 * By Ben Beltran *
6 *********************/
7
8 /******************************
9 * CHANGELOG *
10 *******************************
11 * 0.1 -> Initial Release *
12 * 0.2 -> Config options *
13 * 0.3 -> Day and Night *
14 * 0.4 -> Fancy Canvas Version *
15 *******************************/
16
17
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
23
24 /*Color Configuration
25 ********************************/
26 $nightbackground = '#21272A'; //main colors.
27 $daybackground = '#99cce1';
28
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)';
34
35 /*Text Configuration
36 *******************************/
37 $coldstring = 'frío.'; //string for each temperature.
38 $coolstring = 'fresco.';
39 $regularstring = 'regular.';
40 $warmstring = 'cálido.';
41 $hotstring = 'caliente.';
42
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.)';
48
49 /*Temperature Configuration
50 ******************************/
51 $coldlimit = 15; //How many degrees? (celsius)
52 $coollimit = 20;
53 $temperatelimit = 25;
54 $warmlimit = 30;
55
56
57
58 /******************************
59 * DANGER! DANGER! *
60 *******************************
61 * Don't edit below this part *
62 * unless you know what you're *
63 * doing. *
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 *
69 * out of stuff. *
70 *******************************/
71
72
73 $ch = curl_init('http://xoap.weather.com/weather/local/'.$citycode.'?cc=*&link=xoap&prod=xoap&par='.$partnerid.'&key='.$license.''); //Initialize curl.
74
75 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); //More curl config
76 curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 4);
77
78 $data = curl_exec($ch); //this is your xml stuff
79 curl_close($ch);
80
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:
95 $sky = 2;
96 break;
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:
100 case 33: case 34:
101 $sky = 1;
102 break;
103 default:
104 $sky = 0;
105 }
106 $feelslike = ($feelslike -32)*5/9; //Convert fahrenheit to celsius.
107
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> &middot; ';
110 $sponsors .= '<a href="'.$xml->lnks->link[1]->l.'">'.$xml->lnks->link[1]->t.'</a> &middot; ';
111 $sponsors .= '<a href="'.$xml->lnks->link[2]->l.'">'.$xml->lnks->link[2]->t.'</a> &middot; ';
112 $sponsors .= '<a href="'.$xml->lnks->link[3]->l.'">'.$xml->lnks->link[3]->t.'</a>';
113
114
115 if(isset($_GET['temp'])){
116 $feelslike = $_GET['temp']; //This overrides the weather.com temperature for debugging.
117 }
118 if(isset($_GET['now'])){
119 $now = $_GET['now']; //This overrides the weather.com date for debugging.
120 }
121 if(isset($_GET['sky'])){ //This overrides the weather.com sky conditions for debugging.
122 $sky = $_GET['sky'];
123 }
124
125
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">';
129 ?>
130
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">
133 <head>
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">
137 *{
138 padding: 0;
139 margin: 0;
140 }
141
142 body{
143 font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
144 text-align: center;
145 <?php
146 if($now > $sunrise && $now < $sunset){
147 echo 'background-color:'.$daybackground.';';
148 }else{
149 echo 'background-color:'.$nightbackground.';';
150 }
151 ?>
152 }
153
154 #container{
155 width: 960px;
156 margin: auto;
157 text-align: left;
158 }
159
160 h1{
161 color: #c00;
162 margin-top: 50px;
163 margin-left: 200px;
164 font-size: 3em;
165 width: 410px;
166 }
167 </style>
168 <script type="text/javascript">
169 function draw(){
170 var canvas = document.getElementById('theCanvas');
171 var context = canvas.getContext('2d');
172 var gradient;
173
174 //DRAW THE SKYLINE
175 gradient = context.createLinearGradient(0, 600, 0, 300);
176 gradient.addColorStop(0, "rgb(255,255,255)");
177 gradient.addColorStop(1, "rgb(240,240,240)");
178
179 context.fillStyle = gradient;
180 context.beginPath();
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);
223 context.fill();
224
225 //DRAW THE BASELINE.
226 context.strokeStyle = "rgb(96,96,96)";
227 context.beginPath();
228 context.moveTo(0,600);
229 context.lineTo(960,600);
230 context.stroke();
231
232
233 <?php
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";
246 }else{
247 echo 'var tempText = "'.$hotstring.'";'."\n";
248 echo 'var tempColor = "'.$hotcolor.'";'."\n";
249 }
250
251 ?>
252
253 drawTemperature(context,tempText,tempColor);
254
255
256 <?php
257 switch($sky){
258 case 1:
259 echo "drawSun(context);\n drawCloud(context);\n";
260 break;
261 case 2:
262 echo "drawSun(context);\n drawCloud(context);\n drawRain(context);\n";
263 break;
264 default:
265 echo "drawSun(context);\n";
266
267 }
268 ?>
269
270 }
271
272
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);
280 }
281
282 //function to draw the sun.
283 function drawSun(context){
284 context.fillStyle = "rgb(96,96,96)";
285 context.beginPath();
286 context.arc(860,100,50,0,Math.PI*2,true);
287 context.fill();
288 }
289
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)";
295 context.beginPath();
296 context.moveTo(760+(i*40)-(j*40),180+(j*40));
297 context.lineTo(730+(i*40)-(j*40),210+(j*40));
298 context.stroke();
299 }
300 }
301 }
302
303 //function to draw a cloud over the sun
304 function drawCloud(context){
305 context.fillStyle = "rgb(255,255,255)";
306 context.beginPath();
307 context.arc(880,140,35,0,Math.PI*2,true);
308 context.fill();
309 context.beginPath();
310 context.arc(840,130,45,0,Math.PI*2,true);
311 context.fill();
312 context.beginPath();
313 context.arc(790,145,30,0,Math.PI*2,true);
314 context.fill();
315 context.beginPath();
316 context.arc(800,110,35,0,Math.PI*2,true);
317 context.fill();
318 context.beginPath();
319 context.arc(775,125,25,0,Math.PI*2,true);
320 context.fill();
321 }
322 </script>
323 </head>
324 <body onload="draw();">
325 <div id="container">
326 <canvas id="theCanvas" width="960px" height="600px"></canvas>
327 </div>
328 </body>
329 </html>