Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

Yahoo Vremenska Prognoza

[es] :: PHP :: Yahoo Vremenska Prognoza

[ Pregleda: 8829 | Odgovora: 4 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

balkan7

Član broj: 119255
Poruke: 82
85.30.71.*



Profil

icon Yahoo Vremenska Prognoza17.03.2008. u 15:40 - pre 195 meseci
zanima me kako mogu dobit rezultat za dan koi smo i za sledeci dan a ne za svi u yahoo weather script ?

vreme.php
Code:
<html>
<head>
</head>
<body>
<?
//============================================================================
//============================================================================
// Script:        PHP Script "Yahoo Weather Demo"
//============================================================================
// From:    www.voegeli.li
// Autor:    marco voegeli, switzerland - >> www.voegeli.li >>
// Date:    28-Oct-2005 
// License/
// Usage:    Open Source / for free    
//============================================================================
// DESCRIPTION:
// This Script is the example of the class yahoo weather! It shows all
// attributes of the class ad shows how to use it!
//============================================================================
// Modified: Dec 2006 by Matt Brown
//============================================================================
// Visit http://dowdybrown.com , the contributor of the new version. Thank you
// Matt for this great and better version of the yahoo weather class! You have
// done a good job!
//============================================================================


// ------------------- 
// INCLUDES
// -------------------
include("class.xml.parser.php");
include("class.weather.php");

// ------------------- 
// LOGIC
// -------------------
// Create the new weather object!
// CIXX0020 = Location Code from weather.yahoo.com
// 3600     = seconds of cache lifetime (expires after that)
// C        = Units in Celsius! (Option: F = Fahrenheit)

$timeout=3*60*60;  // 3 hours
if (isset($_ENV["TEMP"]))
  $cachedir=$_ENV["TEMP"];
else if (isset($_ENV["TMP"]))
  $cachedir=$_ENV["TMP"];
else if (isset($_ENV["TMPDIR"]))
  $cachedir=$_ENV["TMPDIR"];
else
// Default Cache Directory  
  $cachedir="/tmp";
  
$cachedir=str_replace('\\\\','/',$cachedir);
if (substr($cachedir,-1)!='/') $cachedir.='/';

$weather_chile = new weather("MKXX0004", 3600, "C", $cachedir);

// Parse the weather object via cached
// This checks if there's an valid cache object allready. if yes
// it takes the local object data, what's much FASTER!!! if it
// is expired, it refreshes automatically from rss online!
$weather_chile->parsecached(); // => RECOMMENDED!

// allway refreshes from rss online. NOT SO FAST. 
//$weather_chile->parse(); // => NOT recommended!


// ------------------- 
// OUTPUT
// -------------------

for ($day=0; isset($weather_chile->forecast[$day]); $day++) {
  print "<h1>Forecast Day $day</h1>";
  //print_r($weather_chile->forecast[$day]);
  print "day: ".$weather_chile->forecast[$day]['DAY']."<br>";      // Wed
  print "date: ".$weather_chile->forecast[$day]['DATE']."<br>";    // 26 Oct 2005
  print "low °C: ".$weather_chile->forecast[$day]['LOW']."<br>";   // 8
  print "high °C: ".$weather_chile->forecast[$day]['HIGH']."<br>"; // 19
  print "text: ".$weather_chile->forecast[$day]['TEXT']."<br>";    // Partly Cloudy
  print "imgcode: ".$weather_chile->forecast[$day]['CODE']."<br>"; // 29=Image for partly cloudy
  print "image: <img src=http://us.i1.yimg.com/us.yimg.com/i/us/we/52/".$weather_chile->forecast[$day]['CODE'].".gif>";
  print "<hr>";
}

?>
</body>
</html>
 
Odgovor na temu

balkan7

Član broj: 119255
Poruke: 82
85.30.71.*



Profil

icon Re: Yahoo Vremenska Prognoza17.03.2008. u 22:16 - pre 195 meseci
evo sta zelim,
 
Odgovor na temu

agvozden
Aleksandar Gvozden
founder
Info-G
Beograd

Član broj: 37813
Poruke: 1123
*.ptt.yu.

Sajt: www.gvozden.info


+68 Profil

icon Re: Yahoo Vremenska Prognoza18.03.2008. u 08:38 - pre 195 meseci
A sta su ti ove klase:

include("class.xml.parser.php");
include("class.weather.php");

imaju li neki komentar??
 
Odgovor na temu

balkan7

Član broj: 119255
Poruke: 82
85.30.71.*



Profil

icon Re: Yahoo Vremenska Prognoza18.03.2008. u 14:38 - pre 195 meseci
evo kod:

class.xml.praser.php
Code:
<?
//============================================================================
//============================================================================
// Script:        PHP Class "xmlParser"
//============================================================================
// From:    http://ch2.php.net/xml
// Autor:    monte at NOT-SP-AM dot ohrt dot com
// Date:    14-Sep-2005 06:48 
// License/
// Usage:    Open Source / for free    
//============================================================================
// DESCRIPTION:
// This is a class for XML parsing with an URL input. It does:
// -  Get File from URL (XML/RSS-File)
// -  Parsing the file into array
// -  Return Array
//============================================================================
//============================================================================


class xmlParser{

// *** ----------------------------------------------------------------
// DECLARATION
var $xml_obj = null;
var $output = array();


// *** ----------------------------------------------------------------
// CONSTRUCTOR
function xmlParser(){

$this->xml_obj = xml_parser_create();
xml_set_object($this->xml_obj,$this);
xml_set_character_data_handler($this->xml_obj, 'dataHandler'); 
xml_set_element_handler($this->xml_obj, "startHandler", "endHandler");




// *** ----------------------------------------------------------------
function parse($path){

if (!($fp = fopen($path, "r"))) {
die("Cannot open XML data file: $path");
return false;
}

while ($data = fread($fp, 4096)) {
if (!xml_parse($this->xml_obj, $data, feof($fp))) {
die(sprintf("XML error: %s at line %d",
xml_error_string(xml_get_error_code($this->xml_obj)),
xml_get_current_line_number($this->xml_obj)));
xml_parser_free($this->xml_obj);
}
}

return true;
}


// *** ----------------------------------------------------------------
function startHandler($parser, $name, $attribs){
$_content = array('name' => $name);
if(!empty($attribs))
$_content['attrs'] = $attribs;
array_push($this->output, $_content);
}

// *** ----------------------------------------------------------------
function dataHandler($parser, $data){
if(!empty($data)) {
$_output_idx = count($this->output) - 1;
$this->output[$_output_idx]['content'] = $data;
}
}

// *** ----------------------------------------------------------------
function endHandler($parser, $name){
if(count($this->output) > 1) {
$_data = array_pop($this->output);
$_output_idx = count($this->output) - 1;
$this->output[$_output_idx]['child'][] = $_data;

}

// *** ----------------------------------------------------------------
function GetNodeByPath($path,$tree = false) {
if ($tree) {
$tree_to_search = $tree;
}
else {
$tree_to_search = $this->output;
}

if ($path == "") {
return null; 
}

$arrPath = explode('/',$path);

foreach($tree_to_search as $key => $val) {
if (gettype($val) == "array") {
$nodename = $val[name];

if ($nodename == $arrPath[0]) { 

if (count($arrPath) == 1) { 
return $val;


array_shift($arrPath);

$new_path = implode($arrPath,"/");

return $this->GetNodeByPath($new_path,$val[child]);
}
}
}
}
} // class : end
?> 


class.weather.php
Code:

<?
//============================================================================
//============================================================================
// Script:        PHP Class "weather"
// Version:     2.0 / 12.12.2006
//
// Rewritten: Dec 2006 by Matt Brown
//   fixed all PHP warnings
//   added cachedir parameter
//   changed structure of results
//   more adaptive to changes in Yahoo RSS feed
//============================================================================
// From:    http://www.voegeli.li
// Autor:    Marco Voegeli, Switzerland >> www.voegeli.li >> fly forward! >>
// Date:    28-Oct-2005 
// License/
// Usage:    Open Source / for free    
//============================================================================
// DEPENDENCIES:
// -  It requires the class "xmlParser" (Be lucky: Also in the Archive file!)
//============================================================================
// DESCRIPTION:
// This Class gets Weather RSS from WEATHER.YAHOO.COM and parses it into
// a weather object with usable attributes. Use it for:
//
// - Actual Situation (temperature/sunrise/sunset/Image...)
// - Forecast Day 1 (temp low, high/text/date/day/image...)
// - Forecast Day 2 (temp low, high/text/date/day/image...)
//
// PUBLIC METHODS
// - parse() :        Gets the XML File parses it and fills attributes
// - parsecahed() :     Much quicker!!! Writes a cached version to a local
//                file with expiry date! expiry date is calculated
//                with the given input parameter
//        
//============================================================================
// SAMPLE:
// - See the file "weather.test.php" in this archive for Santiago de Chile
//
// WEB GUI URL: http://weather.yahoo.com/forecast/CIXX0020_c.html?force_units=1
// RSS URL:     http://xml.weather.yahoo.com/forecastrss?u=C&p=CIXX0020
//
// The class needs one Attribute in the Constructor Method:
//
// $weather_chile = new weather("CIXX0020", 60);
//
// "CIXX0020" is the Yahoo code for Santiago de Chile. See WEB GUI URL above!
// 
// "60" means 60 seconds until the cache expires. If not needed set = 0.
//
// GO TO WEATHER.YAHOO.COM and search for your desired weather location. If
// found, click on the location link (must see the forecast). Now take
// the code from the URL in your browsers address field.
//
//============================================================================
// Changes:
// - 19.11.2005 MAV : XML Feed Structure from Yahoo changed. Adapted script.
//============================================================================
// Visit http://dowdybrown.com , the contributor of the new version. Thank you
// Matt for this great and better version of the yahoo weather class! You have
// done a good job!
//============================================================================



class weather
{


// ------------------- 
// ATTRIBUTES DECLARATION
// -------------------

// HANDLING ATTRIBUTES
var $locationcode; // Yahoo Code for Location
var $allurl;       // generated url with location
var $parser;       // Instance of Class XML Parser
var $unit;         // F or C / Fahrenheit or Celsius

// CACHING ATTRIBUTES
var $cache_expires;
var $cache_lifetime;
var $source;       // cache or live

var $forecast=array();


// ------------------- 
// CONSTRUCTOR METHOD
// -------------------
function weather($location, $lifetime, $unit, $cachedir)
{

// Set Lifetime / Locationcode
$this->cache_lifetime = $lifetime;
$this->locationcode   = $location;
$this->unit           = $unit;
$this->cachedir       = $cachedir;
$this->filename       = $cachedir . $location;

}

// ------------------- 
// FUNCTION PARSE
// -------------------
function parse()
{
$this->allurl = "http://xml.weather.yahoo.com/forecastrss";
$this->allurl .= "?u=" . $this->unit;
$this->allurl .= "&p=" . $this->locationcode;

// Create Instance of XML Parser Class
// and parse the XML File
$this->parser = new xmlParser();
$this->parser->parse($this->allurl);
$content=&$this->parser->output[0]['child'][0]['child'];
foreach ($content as $item) {
  //print "<hr><pre>";
  //print_r($item);
  //print "</pre></p>";
  switch ($item['name']) {
    case 'TITLE':
    case 'LINK':
    case 'DESCRIPTION':
    case 'LANGUAGE':
    case 'LASTBUILDDATE':
      $this->forecast[$item['name']]=$item['content'];
      break;
    case 'YWEATHER:LOCATION':
    case 'YWEATHER:UNITS':
    case 'YWEATHER:ASTRONOMY':
      foreach ($item['attrs'] as $attr=>$value)
        $this->forecast[$attr]=$value;
      break;
    case 'IMAGE':
      break;
    case 'ITEM':
      foreach ($item['child'] as $detail) {
        switch ($detail['name']) {
          case 'GEO:LAT':
          case 'GEO:LONG':
          case 'PUBDATE':
            $this->forecast[$detail['name']]=$detail['content'];
            break;
          case 'YWEATHER:CONDITION':
            $this->forecast['CURRENT']=$detail['attrs'];
            break;
          case 'YWEATHER:FORECAST':
            array_push($this->forecast,$detail['attrs']);
            break;
        }
      }
      break;
  }
}
$this->source = 'live';

// FOR DEBUGGING PURPOSES
//print "<hr><pre>";
//print_r($this->forecast);
//print "</pre></p>";
}

// ------------------- 
// WRITE OBJECT TO CACHE
// -------------------
function writecache() {
  unset($this->parser);
  $this->cache_expires = time() + $this->cache_lifetime;
  $fp = fopen($this->filename, "w");
  fwrite($fp, serialize($this));
  fclose($fp);
}

// ------------------- 
// READ OBJECT FROM CACHE
// -------------------
function readcache()
{
$content=@file_get_contents($this->filename);
if ($content==false) return false;
$intweather = unserialize($content);
if ($intweather->cache_expires < time()) return false;

$this->source = 'cache';
$this->forecast = $intweather->forecast;
return true;
}


// ------------------- 
// FUNCTION PARSECACHED
// -------------------
function parsecached() {
  if ($this->readcache()) return;
  $this->parse();
  $this->writecache();
}

} // class : end

?>
 
Odgovor na temu

stankons
Stanko Milošev
ise Gmbh, Deutschland
Bonn

Član broj: 99408
Poruke: 231
*.trinet.si.

ICQ: 147767352
Sajt: www.milosev.com


Profil

icon Re: Yahoo Vremenska Prognoza26.03.2008. u 08:31 - pre 195 meseci
Ne znam za yahoo, ali ja sam koristio weather.com.

Ovde bi trebalo da sam sve objasnio:

http://milosev.com/blog/?p=70

Ako imas pitanja, pitaj, slbodno :)
 
Odgovor na temu

[es] :: PHP :: Yahoo Vremenska Prognoza

[ Pregleda: 8829 | Odgovora: 4 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.