]> git.r.bdr.sh - rbdr/r.bdr.sh/blob - jekyll/clima/index.php
Adds titles for collection pages, link to archive
[rbdr/r.bdr.sh] / jekyll / clima / 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 *******************************/
15
16
17 /*Weather.com configuration
18 ********************************/
19 $citycode = 'MXCA0026'; //Zip Code (US) or City code according to weather.com
20 $partnerid = '1140062701'; //Partner ID
21 $license = '5b323d77586070aa'; //License number
22
23 /*Color Configuration
24 ********************************/
25 $nightbackground = '#222'; //main colors.
26 $daybackground = '#fff';
27
28 $daymaincolor = '#666';
29 $nightmaincolor = '#e1e1e1;';
30
31 $taglinecolor = '#999';
32
33 $coldcolor = '#78d6fd'; //Colors for each temperature.
34 $coolcolor = '#1b95fb';
35 $temperatecolor = '#999';
36 $warmcolor = '#ff9226';
37 $hotcolor = '#ff1818';
38
39 /*Text Configuration
40 *******************************/
41 $maintext = 'Ju&aacute;rez est&aacute;:';
42 $title = '&iquest;C&oacute;mo est&aacute; el clima en Ju&aacute;rez?';
43
44 $coldstring = 'frio.'; //string for each temperature.
45 $coolstring = 'fresco.';
46 $temperatestring = 'templado.';
47 $warmstring = 'c&aacute;lido.';
48 $hotstring = 'caliente.';
49
50 $coldtagline = '(abrigate bien.)'; //tagline for each temperature.
51 $cooltagline = '(perfecto para un saco.)';
52 $temperatetagline = '(ni fu ni fa.)';
53 $warmtagline = '(como para estar afuera.)';
54 $hottagline = '(hidr&aacute;tate bien.)';
55
56 /*Temperature Configuration
57 ******************************/
58 $coldlimit = 15; //How many degrees? (celsius)
59 $coollimit = 20;
60 $temperatelimit = 25;
61 $warmlimit = 30;
62
63
64
65 /******************************
66 * DANGER! DANGER! *
67 *******************************
68 * Don't edit below this part *
69 * unless you know what you're *
70 * doing. *
71 *******************************
72 * It's not that hard really. *
73 * but it's better if we leave *
74 * it like it is. Unless you *
75 * like customizing the shit *
76 * out of stuff. *
77 *******************************/
78
79
80 $ch = curl_init('http://xoap.weather.com/weather/local/'.$citycode.'?cc=*&link=xoap&prod=xoap&par='.$partnerid.'&key='.$license.''); //Initialize curl.
81
82 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); //More curl config
83 curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 4);
84
85 $data = curl_exec($ch); //this is your xml stuff
86 curl_close($ch);
87
88 $xml = new SimpleXmlElement($data, LIBXML_NOCDATA); //now let's make an XmlElement
89 $feelslike = $xml->cc->flik; //This is the "Feel's Like temp"
90 $sunset = date('G.i',strtotime($xml->loc->suns));
91 $sunrise = date('G.i',strtotime($xml->loc->sunr));
92 $now = date('G.i',time()-28800);
93 $feelslike = ($feelslike -32)*5/9; //Convert fahrenheit to celsius.
94
95 //now let's get the sponsored links. Stupid EULA.
96 $sponsors = '<a href="'.$xml->lnks->link[0]->l.'">'.$xml->lnks->link[0]->t.'</a> &middot; ';
97 $sponsors .= '<a href="'.$xml->lnks->link[1]->l.'">'.$xml->lnks->link[1]->t.'</a> &middot; ';
98 $sponsors .= '<a href="'.$xml->lnks->link[2]->l.'">'.$xml->lnks->link[2]->t.'</a> &middot; ';
99 $sponsors .= '<a href="'.$xml->lnks->link[3]->l.'">'.$xml->lnks->link[3]->t.'</a>';
100
101
102 if(isset($_GET['temp'])){
103 $feelslike = $_GET['temp']; //This overrides the weather.com temperature for debugging.
104 }
105 if(isset($_GET['now'])){
106 $now = $_GET['now']; //This overrides the weather.com temperature for debugging.
107 }
108
109
110 echo '<?xml version="1.0" encoding="UTF-8"?>
111 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
112 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">';
113 ?>
114
115 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
116 <head>
117 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
118 <title><?php echo $title; ?></title>
119 <style type="text/css">
120 *{
121 padding: 0;
122 margin: 0;
123 }
124
125 body{
126 <?php
127 if($now > $sunrise && $now < $sunset){
128 echo 'background-color:'.$daybackground.';';
129 }else{
130 echo 'background-color:'.$nightbackground.';';
131 }
132 ?>
133 font-family:Helvetica,Arial,sans-serif;
134 <?php
135 if($now > $sunrise && $now < $sunset){
136 echo 'color:'.$daymaincolor.';';
137 }else{
138 echo 'color:'.$nightmaincolor.';';
139 }
140 ?>
141 }
142
143 #container{
144 margin: auto;
145 width: 400px;
146 text-align:center;
147 margin-top:200px;
148 }
149
150 #container p{
151 font-size:4em;
152 padding-left: 24px;
153 }
154
155 #container .rec{
156 font-style: italic;
157 font-size: .6em;
158 letter-spacing: .1em;
159 color: <?php echo $taglinecolor; ?>;
160 }
161
162 #container .cold{
163 color: <?php echo $coldcolor?>;
164 }
165 #container .cool{
166 color: <?php echo $coolcolor?>;
167 }
168 #container .temperate{
169 color: <?php echo $temperatecolor?>;
170 }
171 #container .warm{
172 color: <?php echo $warmcolor?>;
173 }
174 #container .hot{
175 color: <?php echo $hotcolor?>;
176 }
177
178 #footer{
179 color: #999;
180 font-size: .6em;
181 bottom: 0;
182 left: 0;
183 position: absolute;
184 padding: 10px;
185 }
186
187 img{ border: 0; }
188 a{ color: #1b95fb; }
189 </style>
190 </head>
191 <body>
192 <div id="container">
193 <span><?php echo $maintext; ?></span><br/>
194 <?php
195
196 /******************************
197 * DANGER! DANGER! *
198 *******************************
199 * I guess the following part *
200 * is not that dangerous, but *
201 * make sure you know what *
202 * you're doing. *
203 *******************************/
204
205 if($feelslike < $coldlimit){ echo '<p class="cold">'.$coldstring.'</p><span class="rec">'.$coldtagline.'</span>'; }
206 else if($feelslike < $coollimit){ echo '<p class="cool">'.$coolstring.'</p><span class="rec">'.$cooltagline.'</span>'; }
207 else if($feelslike < $temperatelimit){ echo '<p class="temperate">'.$temperatestring.'</p><span class="rec">'.$temperatetagline.'</span>'; }
208 else if($feelslike < $warmlimit){ echo '<p class="warm">'.$warmstring.'</p><span class="rec">'.$warmtagline.'</span>'; }
209 else{ echo '<p class="hot">'.$hotstring.'</p><span class="rec">'.$hottagline.'</span>'; }
210 ?>
211 </div>
212 <!-- <div id="footer">
213 Powered by: <a href="http://weather.com"><img src="TWClogo_31px.png" alt="The Weather Channel" /></a> Sponsored by: <?php echo $sponsors; ?>
214 </div> -->
215 </body>
216 </html>