rss i slike

2

rss i slike

offline
  • igor86  Male
  • Stručni saradnik
    Web programiranje
  • Pridružio: 24 Maj 2006
  • Poruke: 1633

Evo da predpostavim,

Samo nacini za dobijanje podataka iz razlicitih izvora su drugaciji. Prema tome baza ostaje ista, a jako malo se koda mjenja, moguce samo funkcije za parsiranje.

Citat:svakih sat vremena ili

Moguce ali ne bitno.

Ja bih pitao da li svaka vijest ceka approve (sto bi bilo logicno) i na koliko se to radi?



Registruj se da bi učestvovao u diskusiji. Registrovanim korisnicima se NE prikazuju reklame unutar poruka.
offline
  • Pridružio: 24 Mar 2006
  • Poruke: 273
  • Gde živiš: Beograd

igor86 ::Ja bih pitao da li svaka vijest ceka approve (sto bi bilo logicno) i na koliko se to radi?
Meni bas nije logicno, vesti se same "pisu" tako da nema greske a eventualno ako nalete na neku gresku vest obrisu.
A i ko ce da pregleda dnevno ~500 vesti pa da odobrava svaku Smile
To je moje misljenje da sacekamo autora pa nek odgovori Smile



offline
  • Pridružio: 24 Mar 2004
  • Poruke: 3962
  • Gde živiš: Zemun

@igor86
pa ok. baza ista... i gomila koda od jednog izvora moze da se iskoristi za drugi, ali eto zanima me onda koliko je bilo potrebno za prvi izvor Smile
kada se krenulo od 0.... posle za drugi izvor se moze koristiti ceo kod od prvog osim sam nacin vadjenja vesti....

a sto se tice crona... vise sam pitao da vidim koliko je zahtevno to za server....a sto se tice toga da je logicno da se ceka provera... sta znam, ima puno vesti... a svi izvori su manje vise pouzdani tako da ako oni mogu da objave ja bih isao logikom da mogu i ja da objavim tako da ne bih proveravao previse...... eto ja bih to dao cron-u da radi svakoh sat vremena ili pola sata Smile zato i pitam na koliko se to radi zbog opterecenja servera Smile

offline
  • Pridružio: 24 Mar 2006
  • Poruke: 273
  • Gde živiš: Beograd

Evo kolko je meni trebalo ideju sam dobio 15min. prenego otvorim temu, a temu sam otvorio u 13:28 i napravio dok je peca pisao ovaj post sa primerom blica (15:06)... Dakle nekih 90 min.

Sad sam zavrsio i ubcivanje u bazu, povlacenje vesti, naslova itd itd.
Samo se trenutno dvoumim/troumim izmedju nekih varijanti kako to sve daintegrisem u portal ali gllavni deo je gotov.

Ja sam radio samo za mondo jer me iz njega trebaju sportske vesti.
Bacio sam pogled i na kurirov sajt i mislim da i za njega nije problem odraditi samo sto mi se ne svidja jedna stvar kod njih, nemaju slike za sve vesti tako da on otpada Smile

ps. ja se izvinjavam stoo u mijim postovima ima duplih slova i sl. przne su mi baterije u tastaturi paa malo trrokira :Smile

offline
  • igor86  Male
  • Stručni saradnik
    Web programiranje
  • Pridružio: 24 Maj 2006
  • Poruke: 1633

@Svemirko

Ok, sve jasno. Inace nije to neko opterecenje za server, samo je tu bandwith u pitanju. Treba napomenuti da se trebaju postovati autorska prava tih portala Smile

offline
  • Pridružio: 24 Mar 2006
  • Poruke: 273
  • Gde živiš: Beograd

Imam jedan problem koji od sinoc ne mogu da resim...
Naime za citanje rss-a koristim OVAJ feed parser i sve radi perfektno sem sto mi u bazu umesto navodnika ubacuje kod koji protom nije potpun "#8221".

evo da postavim i ovde kod da ne skidate pa pogledajte mozda nadjete neku gresku...
<?php /* HOW TO USE ----------------------------------------------------------------------- It's very easy to use. Just follow this 3 steps: 1. Include the file    include('FeedParser.php'); 2. Create an object of FeedParser class    $Parser = new FeedParser(); 3. Parse the URL you want to featch    $Parser->parse('http://www.sitepoint.com/rss.php');     Done. Now you can use this functions to get various information of parsed feed:    1. $Parser->getChannels()        - To get all channel elements as array    2. $Parser->getItems()           - To get all feed elements as array    3. $Parser->getChannel($name)    - To get a channel element by name    4. $Parser->getItem($index)      - To get a feed element as array by it's index    5. $Parser->getTotalItems()      - To get the number of total feed elements    6. $Parser->getFeedVersion()     - To get the detected version of parsed feed    7. $Parser->getParsedUrl()       - To get the parsed feed URL      ======================================================================= IMPORTANT NOTES ----------------------------------------------------------------------- 1. All array keys are must be UPPERCASE 2. All dates are converted to timestamp 3. Attributes of a tag will be found under TAGNAME_ATTRS index    example: Attributes of $item['GUID'] will be found as $item['GUID_ATTRS'] 4. The tags which have subtags will be an array and sub tags will be found as it's element    example: IMAGE tag in RSS 2.0 ======================================================================== */ class FeedParser{           private $xmlParser      = null;    private $insideItem     = array();                  // Keep track of current position in tag tree    private $currentTag     = null;                     // Last entered tag name         private $currentAttr    = null;                     // Attributes array of last entered tag        private $namespaces     = array(                      'http://purl.org/rss/1.0/'                  => 'RSS 1.0',                      'http://purl.org/rss/1.0/modules/content/'  => 'RSS 2.0',                      'http://www.w3.org/2005/Atom'               => 'ATOM 1',                      );                          // Namespaces to detact feed version    private $itemTags       = array('ITEM','ENTRY');    // List of tag names which holds a feed item    private $channelTags    = array('CHANNEL','FEED');  // List of tag names which holds all channel elements    private $dateTags       = array('UPDATED','PUBDATE','DC:DATE');     private $hasSubTags     = array('IMAGE','AUTHOR');  // List of tag names which have sub tags    private $channels       = array();                     private $items          = array();    private $itemIndex      = 0;    private $url            = null;                     // The parsed url    private $version        = null;                     // Detected feed version               /**    * Constructor - Initialize and set event handler functions to xmlParser    */       function __construct()    {       $this->xmlParser = xml_parser_create();              xml_set_object($this->xmlParser, $this);       xml_set_element_handler($this->xmlParser, "startElement", "endElement");       xml_set_character_data_handler($this->xmlParser, "characterData");    }       /*-----------------------------------------------------------------------+    |  Public functions. Use to parse feed and get informations.             |       +-----------------------------------------------------------------------*/        /**    * Get all channel elements       *    * @access   public    * @return   array   - All chennels as associative array    */    public function getChannels()    {       return $this->channels;    }        /**    * Get all feed items       *    * @access   public    * @return   array   - All feed items as associative array    */    public function getItems()    {       return $this->items;    }    /**    * Get total number of feed items    *    * @access   public    * @return   number     */       public function getTotalItems()    {       return count($this->items);    }    /**    * Get a feed item by index    *    * @access   public    * @param    number  index of feed item    * @return   array   feed item as associative array of it's elements    */       public function getItem($index)    {       if($index < $this->getTotalItems())       {          return $this->items[$index];       }       else       {          throw new Exception("Item index is learger then total items.");          return false;       }           }        /**    * Get a channel element by name    *    * @access   public    * @param    string  the name of channel tag    * @return   string    */       public function getChannel($tagName)    {       if(array_key_exists(strtoupper($tagName), $this->channels))       {          return $this->channels[strtoupper($tagName)];       }       else       {          throw new Exception("Channel tag $tagName not found.");          return false;       }    }        /**    * Get the parsed URL    *    * @access   public    * @return   string    */       public function getParsedUrl()    {       if(empty($this->url))       {          throw new Exception("Feed URL is not set yet.");          return FALSE;       }       else       {          return $this->url;       }                  }    /**    * Get the detected Feed version    *    * @access   public    * @return   string    */       public function getFeedVersion()    {       return $this->version;    }        /**    * Parses a feed url    *    * @access   public    * @param    srting  teh feed url    * @return   void    */       public function parse($url)    {       $this->url  = $url;       $URLContent = $this->getUrlContent();              if($URLContent)       {             $segments   = str_split($URLContent, 4096);          foreach($segments as $index=>$data)          {             $lastPiese = ((count($segments)-1) == $index)? true : false;             xml_parse($this->xmlParser, $data, $lastPiese)                or die(sprintf("XML error: %s at line %d",                 xml_error_string(xml_get_error_code($this->xmlParser)),                 xml_get_current_line_number($this->xmlParser)));          }          xml_parser_free($this->xmlParser);          }       else       {          die('Sorry! cannot load the feed url.');          }              if(empty($this->version))       {          die('Sorry! cannot detect the feed version.');       }    }           // End public functions -------------------------------------------------        /*-----------------------------------------------------------------------+    | Private functions. Be careful to edit them.                            |       +-----------------------------------------------------------------------*/    /**    * Load the whole contents of a RSS/ATOM page    *    * @access   private    * @return   string    */    private function getUrlContent()    {       if(empty($this->url))       {          throw new Exception("URL to parse is empty!.");          return false;       }           if($content = @file_get_contents($this->url))       {          return $content;       }       else       {          $ch         = curl_init();                    curl_setopt($ch, CURLOPT_URL, $this->url);          curl_setopt($ch, CURLOPT_HEADER, false);          curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);          $content    = curl_exec($ch);          $error      = curl_error($ch);                    curl_close($ch);                    if(empty($error))          {             return $content;             }          else          {             throw new Exception("Erroe occured while loading url by cURL. <br />\n" . $error) ;             return false;          }       }        }        /**    * Handle the start event of a tag while parsing    *    * @access   private    * @param    object  the xmlParser object    * @param    string  name of currently entering tag    * @param    array   array of attributes    * @return   void    */    private function startElement($parser, $tagName, $attrs)    {       if(!$this->version)       {          $this->findVersion($tagName, $attrs);       }                     array_push($this->insideItem, $tagName);              $this->currentTag  = $tagName;       $this->currentAttr = $attrs;    }       /**    * Handle the end event of a tag while parsing    *    * @access   private    * @param    object  the xmlParser object    * @param    string  name of currently ending tag    * @return   void    */       private function endElement($parser, $tagName)    {          if (in_array($tagName, $this->itemTags))       {          $this->itemIndex++;       }              array_pop($this->insideItem);       $this->currentTag = $this->insideItem[count($this->insideItem)-1];    }       /**    * Handle character data of a tag while parsing    *    * @access   private    * @param    object  the xmlParser object    * @param    string  tag value    * @return   void    */    private function characterData($parser, $data)    {       //Converting all date formats to timestamp       if(in_array($this->currentTag, $this->dateTags))       {          $data = strtotime($data);       }                    if($this->inChannel())       {          // If has subtag, make current element an array and assign subtags as it's element          if(in_array($this->getParentTag(), $this->hasSubTags))           {             if(! is_array($this->channels[$this->getParentTag()]))             {                $this->channels[$this->getParentTag()] = array();             }             $this->channels[$this->getParentTag()][$this->currentTag] .= strip_tags($this->unhtmlentities((trim($data))));             return;          }          else          {             if(! in_array($this->currentTag, $this->hasSubTags))              {                $this->channels[$this->currentTag] .= strip_tags($this->unhtmlentities((trim($data))));             }          }                             if(!empty($this->currentAttr))          {             $this->channels[$this->currentTag . '_ATTRS'] = $this->currentAttr;                                   //If the tag has no value             if(strlen($this->channels[$this->currentTag]) < 2)             {                //If there is only one attribute, assign the attribute value as channel value                if(count($this->currentAttr) == 1)                {                   foreach($this->currentAttr as $attrVal)                   {                      $this->channels[$this->currentTag] = $attrVal;                   }                }                //If there are multiple attributes, assign the attributs array as channel value                else                {                   $this->channels[$this->currentTag] = $this->currentAttr;                }                                    }          }       }       elseif($this->inItem())       {          // If has subtag, make current element an array and assign subtags as it's elements          if(in_array($this->getParentTag(), $this->hasSubTags))           {             if(! is_array($this->items[$this->itemIndex][$this->getParentTag()]))             {                $this->items[$this->itemIndex][$this->getParentTag()] = array();             }             $this->items[$this->itemIndex][$this->getParentTag()][$this->currentTag] .= strip_tags($this->unhtmlentities((trim($data))));             return;          }          else          {             if(! in_array($this->currentTag, $this->hasSubTags))              {                $this->items[$this->itemIndex][$this->currentTag] .= strip_tags($this->unhtmlentities((trim($data))));             }          }                              if(!empty($this->currentAttr))          {             $this->items[$this->itemIndex][$this->currentTag . '_ATTRS'] = $this->currentAttr;                                   //If the tag has no value                          if(strlen($this->items[$this->itemIndex][$this->currentTag]) < 2)             {                //If there is only one attribute, assign the attribute value as feed element's value                if(count($this->currentAttr) == 1)                {                   foreach($this->currentAttr as $attrVal)                   {                      $this->items[$this->itemIndex][$this->currentTag] = $attrVal;                   }                }                //If there are multiple attributes, assign the attribute array as feed element's value                else                {                   $this->items[$this->itemIndex][$this->currentTag] = $this->currentAttr;                }                                    }          }       }    }    /**    * Find out the feed version    *    * @access   private    * @param    string  name of current tag    * @param    array   array of attributes    * @return   void    */       private function findVersion($tagName, $attrs)    {       $namespace = array_values($attrs);       foreach($this->namespaces as $value =>$version)       {          if(in_array($value, $namespace))          {             $this->version = $version;             return;          }          }    }        private function getParentTag()    {       return $this->insideItem[count($this->insideItem) - 2];    }    /**    * Detect if current position is in channel element    *    * @access   private    * @return   bool    */       private function inChannel()    {       if($this->version == 'RSS 1.0')       {          if(in_array('CHANNEL', $this->insideItem) && $this->currentTag != 'CHANNEL')          return TRUE;       }       elseif($this->version == 'RSS 2.0')       {          if(in_array('CHANNEL', $this->insideItem) && !in_array('ITEM', $this->insideItem) && $this->currentTag != 'CHANNEL')          return TRUE;          }       elseif($this->version == 'ATOM 1')       {          if(in_array('FEED', $this->insideItem) && !in_array('ENTRY', $this->insideItem) && $this->currentTag != 'FEED')          return TRUE;          }              return FALSE;    }    /**    * Detect if current position is in Item element    *    * @access   private    * @return   bool    */       private function inItem()    {       if($this->version == 'RSS 1.0' || $this->version == 'RSS 2.0')       {          if(in_array('ITEM', $this->insideItem) && $this->currentTag != 'ITEM')          return TRUE;       }       elseif($this->version == 'ATOM 1')       {          if(in_array('ENTRY', $this->insideItem) && $this->currentTag != 'ENTRY')          return TRUE;          }              return FALSE;    }       //This function is taken from lastRSS    /**    * Replace HTML entities &something; by real characters    *    *    * @access   private    * @author   Vojtech Semecky <webmaster@oslab.net>    * @link     http://lastrss.oslab.net/    * @param    string    * @return   string    */       private function unhtmlentities($string)    {       // Get HTML entities table       $trans_tbl = get_html_translation_table (HTML_ENTITIES, ENT_QUOTES);       // Flip keys<==>values       $trans_tbl = array_flip ($trans_tbl);       // Add support for &apos; entity (missing in HTML_ENTITIES)       $trans_tbl += array('&apos;' => "'");       // Replace entities by values       return strtr ($string, $trans_tbl);    } } //End class FeedParser ?>

offline
  • Peca  Male
  • Glavni Administrator
  • Predrag Damnjanović
  • SysAdmin i programer
  • Pridružio: 17 Apr 2003
  • Poruke: 23211
  • Gde živiš: Niš

Svemirko ::a mene zanima peco koliko si dugo radio kod recimo za jedan izvor Smile

pa vidi, ja sam gore dao opsti algoritam za cupanje slika sa sajta.
kapiras li da, kada napises taj opsti algoritam, ostaje ti samo da za svaki izvor upises string koji oznacava kraj vesti.
dakle... minut posla po izvoru Smile

Svemirko ::i na koliko cron izvrsava skriptu ? svakih sat vremena ili ?
cron na svaki sat.
sve se zavrsi za nekih 15 min [pauza iza svakog http requesta je po 2 sec, pa mnozi broj obidjenih novih stranica plus request za skidanje slike]

Dopuna: 04 Avg 2008 13:21

igor86 ::Ja bih pitao da li svaka vijest ceka approve (sto bi bilo logicno) i na koliko se to radi?
Zasto approve za vesti iz pouzdanih izvora? Smile

Dopuna: 04 Avg 2008 13:29

Svemirko ::@igor86
pa ok. baza ista... i gomila koda od jednog izvora moze da se iskoristi za drugi, ali eto zanima me onda koliko je bilo potrebno za prvi izvor Smile
kada se krenulo od 0.... posle za drugi izvor se moze koristiti ceo kod od prvog osim sam nacin vadjenja vesti....


Od nule - treba mnoooooogo smešak
Pa od prilike, mesec dana umerenog programiranja - za kompletan sajt.

Svemirko ::a sto se tice crona... vise sam pitao da vidim koliko je zahtevno to za server....
http request-evi i upis u bazu nisu zahtevni.
ali ono sto je pain-in-the-ass za server je ubacivanje svake vesti u search index Smile

Dopuna: 04 Avg 2008 13:34

Marko_88 ::odraditi samo sto mi se ne svidja jedna stvar kod njih, nemaju slike za sve vesti tako da on otpada Smile

zasto otpada?
ako vest nema sliku - sto bi otpala?
vest bez slike bude i kod tebe.

Dopuna: 04 Avg 2008 13:38

igor86 ::Ok, sve jasno. Inace nije to neko opterecenje za server, samo je tu bandwith u pitanju. Treba napomenuti da se trebaju postovati autorska prava tih portala Smile
bandwidth koji moj bot trosi je verovatno u promilima u odnosu na bandwidth koji posetioci mog sajta potrose citajuci te vesti Smile

a autorska prava... pa pitas ih za dozvolu.
a kad postanes posecen - onda oni tebe jure da ih ubacis na svoj sajt Smile

Blicu isporucim 900 posetioca dnevno.
pa vi sad vidite da li im se ne isplati da ih prenosim Very Happy

p.s. Vesti.rs su dostigle 9.000 unikatnih poseta dnevno, i idu dalje smešak

offline
  • Pridružio: 24 Mar 2006
  • Poruke: 273
  • Gde živiš: Beograd

Peca ::
Marko_88 ::odraditi samo sto mi se ne svidja jedna stvar kod njih, nemaju slike za sve vesti tako da on otpada Smile

zasto otpada?
ako vest nema sliku - sto bi otpala?
vest bez slike bude i kod tebe.

To stoji naravno, ne pravim nista ozbiljno pa da po svaku cenu moram da uzmem vest od kurira ili nekog drugog ko nema slike u svakoj vesti.
Nekako mi je lepse kada je sve identicno tj. kada svaka vest ima sliku.

Elem, naso sam resenje problema sa ubacivanjem u bazu...
I ne mogu da verujem da sam 2 dana gubio vreme na nista, onaj kod mislim da sam vise i napamet naucio i problem nsam naso, problem je u mondu izgleda da im navodnci prave problem GUZ - Glavom U Zid

offline
  • igor86  Male
  • Stručni saradnik
    Web programiranje
  • Pridružio: 24 Maj 2006
  • Poruke: 1633

Peca ::
igor86 ::Ja bih pitao da li svaka vijest ceka approve (sto bi bilo logicno) i na koliko se to radi?
Zasto approve za vesti iz pouzdanih izvora? Smile


Hm pa recimo ima dozu ozbiljnosti Ziveli

pogledaj

http://www.vesti.rs/Sport/Milorad-Cavic-u-finalu-2.html

Grabovana je cini mi se pogresna slika

Ko je trenutno na forumu
 

Ukupno su 698 korisnika na forumu :: 38 registrovanih, 7 sakrivenih i 653 gosta   ::   [ Administrator ] [ Supermoderator ] [ Moderator ] :: Detaljnije

Najviše korisnika na forumu ikad bilo je 3466 - dana 01 Jun 2021 17:07

Korisnici koji su trenutno na forumu:
Korisnici trenutno na forumu: Andrija357, cavatina, cemix, Dannyboy, darkstar101, dekan.m, Denaya, DPera, Excalibur13, Georgius, Hans Gajger, HrcAk47, ivica976, kalens021, ksyyaj, kybonacci, ladro, Luka Blažević, Marko Marković, milutin134, Mixelotti, NoOneEver Dreams, Panter, panzerwaffe, pera bager, pristinski korpus, raptorsi, rodoljub, slonic_tonic, sokars, solic, srbijaiznadsvega, stegonosa, theNedjeljko, Tvrtko I, wizzardone, YU-UKI, šumar bk2