Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?
- /*
- author: bluescreen
- license: http://creativecommons.org/licenses/by-nc-sa/3.0/
- */
- $id = 0;
- if(isset($_GET['city']) && !empty($_GET['city'])) $id = $_GET['city'];
- $BASE_URL = "http://query.yahooapis.com/v1/public/yql";
- switch($id)
- {
- case 0: $yql_query = 'select item.condition from weather.forecast where woeid in (select woeid from geo.places(1) where text="los angeles, ca")';
- break;
- case 1: $yql_query = 'select item.condition from weather.forecast where woeid in (select woeid from geo.places(1) where text="las vegas, nv")';
- break;
- case 2: $yql_query = 'select item.condition from weather.forecast where woeid in (select woeid from geo.places(1) where text="san francisco, ca")';
- break;
- case 3: $yql_query = 'select item.condition from weather.forecast where woeid in (select woeid from geo.places(1) where text="sausalito, ca")';
- break;
- }
- $yql_query_url = $BASE_URL . "?q=" . urlencode($yql_query) . "&format=json";
- // Make call with cURL
- $session = curl_init($yql_query_url);
- curl_setopt($session, CURLOPT_RETURNTRANSFER,true);
- $json = curl_exec($session);
- // Convert JSON to PHP object
- $phpObj = json_decode($json, true);
- switch($phpObj['query']['results']['channel']['item']['condition']['code'])
- {
- case 0:
- case 1:
- case 2:
- case 3:
- case 4:
- case 23:
- case 24:
- case 37:
- case 38:
- case 39:
- case 45:
- case 47: $weather = 'Description: Gewitter</br>ID: 16';//16
- break;
- case 8:
- case 9:
- case 10:
- case 11:
- case 12:
- case 17:
- case 35:
- case 40: $weather = 'Description: Regenschauer</br>ID: 8';//8
- break;
- case 13:
- case 15:
- case 16:
- case 41:
- case 42:
- case 43:
- case 5:
- case 6:
- case 7:
- case 14:
- case 18:
- case 46: $weather = 'Description: Schnee</br>ID: 10';
- break;
- case 19: $weather = 'Description: Sandsturm</br>ID: 19';//19
- break;
- case 20:
- case 21:
- case 22: $weather = 'Description: Neblig</br>ID: 9';//9
- break;
- case 27:
- case 29:
- case 28:
- case 30:
- case 44: $weather = 'Description: Leicht Bewölkt</br>ID: 17';//17
- break;
- case 25:
- case 26: $weather = 'Description: Bewölkt</br>ID: 20';//20
- break;
- case 32:
- case 36: $weather = 'Description: Sonnig</br>ID: 1';//1
- break;
- case 31:
- case 33:
- case 34: $weather = 'Description: Klarer Himmel</br>ID: 2';//2
- break;
- case 3200: $weather = 'not available';
- break;
- }
- echo $weather;
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement