Advertisement
_Bluescreen_

real weather (index.php)

Feb 18th, 2016
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.46 KB | None | 0 0
  1. <?
  2.     /*
  3.         author: bluescreen
  4.         license: http://creativecommons.org/licenses/by-nc-sa/3.0/
  5.     */
  6.     $id = 0;
  7.     if(isset($_GET['city']) && !empty($_GET['city'])) $id = $_GET['city'];
  8.     $BASE_URL = "http://query.yahooapis.com/v1/public/yql";
  9.  
  10.     switch($id)
  11.     {
  12.         case 0: $yql_query = 'select item.condition from weather.forecast where woeid in (select woeid from geo.places(1) where text="los angeles, ca")';
  13.             break;
  14.         case 1: $yql_query = 'select item.condition from weather.forecast where woeid in (select woeid from geo.places(1) where text="las vegas, nv")';
  15.             break;
  16.         case 2: $yql_query = 'select item.condition from weather.forecast where woeid in (select woeid from geo.places(1) where text="san francisco, ca")';
  17.             break;
  18.         case 3: $yql_query = 'select item.condition from weather.forecast where woeid in (select woeid from geo.places(1) where text="sausalito, ca")';
  19.             break;
  20.     }
  21.    
  22.     $yql_query_url = $BASE_URL . "?q=" . urlencode($yql_query) . "&format=json";
  23.  
  24.     // Make call with cURL
  25.     $session = curl_init($yql_query_url);
  26.     curl_setopt($session, CURLOPT_RETURNTRANSFER,true);
  27.     $json = curl_exec($session);
  28.     // Convert JSON to PHP object
  29.     $phpObj =  json_decode($json, true);
  30.     switch($phpObj['query']['results']['channel']['item']['condition']['code'])
  31.     {
  32.         case 0:
  33.         case 1:
  34.         case 2:
  35.         case 3:
  36.         case 4:
  37.         case 23:
  38.         case 24:
  39.         case 37:
  40.         case 38:
  41.         case 39:
  42.         case 45:
  43.         case 47: $weather = 'Description: Gewitter</br>ID: 16';//16
  44.             break;
  45.         case 8:
  46.         case 9:
  47.         case 10:
  48.         case 11:
  49.         case 12:
  50.         case 17:
  51.         case 35:
  52.         case 40: $weather = 'Description: Regenschauer</br>ID: 8';//8
  53.             break;
  54.         case 13:
  55.         case 15:
  56.         case 16:
  57.         case 41:
  58.         case 42:
  59.         case 43:
  60.         case 5:
  61.         case 6:
  62.         case 7:
  63.         case 14:
  64.         case 18:
  65.         case 46: $weather = 'Description: Schnee</br>ID: 10';
  66.             break;
  67.         case 19: $weather = 'Description: Sandsturm</br>ID: 19';//19
  68.             break;
  69.         case 20:
  70.         case 21:
  71.         case 22: $weather = 'Description: Neblig</br>ID: 9';//9
  72.             break;
  73.         case 27:
  74.         case 29:
  75.         case 28:
  76.         case 30:
  77.         case 44: $weather = 'Description: Leicht Bewölkt</br>ID: 17';//17
  78.             break;
  79.         case 25:
  80.         case 26: $weather = 'Description: Bew&ouml;lkt</br>ID: 20';//20
  81.             break;
  82.         case 32:
  83.         case 36: $weather = 'Description: Sonnig</br>ID: 1';//1
  84.             break;
  85.         case 31:
  86.         case 33:
  87.         case 34: $weather = 'Description: Klarer Himmel</br>ID: 2';//2
  88.             break;
  89.         case 3200: $weather = 'not available';
  90.         break;
  91.     }
  92.     echo $weather;
  93.  
  94. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement