function RssItems($limit = 10)
 {
     $feed = new RestfulService('http://pipes.yahoo.com/pipes/pipe.run?_id=7479b77882a68cdf5a7143374b51cf30&_render=rss', 7200);
     $feedXML = $feed->request()->getBody();
     // Extract items from feed
     $result = $feed->getValues($feedXML, 'channel', 'item');
     foreach ($result as $item) {
         $item->pubDate = date("D, M jS Y", strtotime($item->pubDate));
     }
     // Return items up to limit
     return $result->getRange(0, $limit);
 }
示例#2
0
 function ImportSpeakersFromSched()
 {
     $feed = new RestfulService('http://openstacksummitoctober2015tokyo.sched.org/api/role/export?api_key=47dfbdc49d82ff16669df259952656fa&role=speaker&format=xml&fields=username,name,email', 7200);
     $feedXML = $feed->request()->getBody();
     $feedXML = preg_replace('/&(?!#?[a-z0-9]+;)/', '&', $feedXML);
     $results = $feed->getValues($feedXML, 'speaker');
     // A new import overwrites previous data.
     // The table is trucated to remove previous entries and avoid duplicates.
     DB::Query("TRUNCATE SchedSpeaker");
     foreach ($results as $item) {
         $Speaker = new SchedSpeaker();
         $Speaker->username = $item->username;
         $Speaker->email = $item->email;
         $Speaker->name = $item->name;
         $Speaker->write();
     }
     echo "Speakers imported successfully.";
 }
示例#3
0
 /**
  * @param string $url
  * @param int  $expiry
  * @param null $collection
  * @param null $element
  * @return ArrayList
  */
 private function queryExternalSource($url, $expiry = 3600, $collection = NULL, $element = NULL)
 {
     $output = new ArrayList();
     try {
         $feed = new RestfulService($url, $expiry);
         $response = $feed->request();
         if ($response->getStatusCode() == 200) {
             $body = $response->getBody();
             $output = $feed->getValues($body, $collection, $element);
         }
     } catch (Exception $ex) {
         SS_Log::log($ex, SS_Log::WARN);
     }
     return $output;
 }
示例#4
0
 /**
  * @param int $limit
  * @return ArrayList
  */
 function rssEvents($limit = 7)
 {
     try {
         $feed = new RestfulService('https://groups.openstack.org/events-upcoming.xml', 7200);
     } catch (Exception $ex) {
         SS_Log::log("It wasn't possible to get rss content from source. Isolated occurrences of this error can be ignored since temporary glitches accessing url could be the cause. Information will be ingested on next run if that's the case", SS_Log::ERR);
         echo $ex->getMessage();
     }
     $feedXML = $feed->request()->getBody();
     // Extract items from feed
     $result = $feed->getValues($feedXML, 'channel', 'item');
     foreach ($result as $item) {
         $item->pubDate = date("D, M jS Y", strtotime($item->pubDate));
         $DOM = new DOMDocument();
         $DOM->loadHTML(html_entity_decode($item->description));
         $span_tags = $DOM->getElementsByTagName('span');
         foreach ($span_tags as $tag) {
             if ($tag->getAttribute('property') == 'schema:startDate') {
                 $item->startDate = $tag->getAttribute('content');
             } else {
                 if ($tag->getAttribute('property') == 'schema:endDate') {
                     $item->endDate = $tag->getAttribute('content');
                 }
             }
         }
         $div_tags = $DOM->getElementsByTagName('div');
         foreach ($div_tags as $tag) {
             if ($tag->getAttribute('property') == 'schema:location') {
                 $item->location = $tag->nodeValue;
             }
         }
     }
     return $result->limit($limit, 0);
 }