Skip to content

Instantly share code, notes, and snippets.

@necenzurat
Created August 23, 2012 13:45
Show Gist options
  • Save necenzurat/3436746 to your computer and use it in GitHub Desktop.
Save necenzurat/3436746 to your computer and use it in GitHub Desktop.
google weather
<?php
/* shits */
header('Content-Type: text/html; charset=utf-8');
set_time_limit(0);
date_default_timezone_set("Europe/Bucharest");
function sopen($url_page){
$ua = "Googlebot/2.1 (+http://www.google.com/bot.html)"; // google :D
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url_page);
curl_setopt($ch, CURLOPT_USERAGENT, $ua);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_SSLVERSION, 3);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt( $ch, CURLOPT_MAXREDIRS, 10 );
$html = curl_exec ( $ch );
curl_close($ch);
return $html;
}
$now = date("H:i");
/* here we go */
$city = "Bucuresti"; //use GET parameter "?city=" appended to this file's URL/AJAX request
$language = "ro"; // ex: ro, en, the parameter is from Google hl=
$request_url = (sopen($request_url = "http://www.google.com/ig/api?hl=$language&weather=$city"));
//simple xml is stupid /w forigen chars
$xml = simplexml_load_string($request_url) or die("Google Weather feed not loading");
$condition = $xml->weather->current_conditions->condition["data"];
$temp = $xml->weather->current_conditions->temp_c["data"]; //change temp_c to temp_f for Fahrenheit
$humidity = mb_strtolower($xml->weather->current_conditions->humidity["data"]);
$wind = ($xml->weather->current_conditions->wind_condition["data"]);
//filter shits
$humidity = substr($humidity, 10);
$wind = substr($wind, 6);
$wind = preg_replace("/la/", "cu", $wind);
//make status
$status = "La ora $now sunt $temp&deg; C, $condition; umiditatea $humidity; vantul bate dinspre $wind. #bucuresti";
echo "$status<br />";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment