Skip to content

Commit

Permalink
[NYTBridge] Fix article parsing (#2106)
Browse files Browse the repository at this point in the history
Co-authored-by: podiki <[email protected]>
  • Loading branch information
corenting and podiki authored Jun 30, 2021
1 parent 9399ebb commit 0de2db8
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions bridges/NYTBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,33 @@ class NYTBridge extends FeedExpander {
const MAINTAINER = 'IceWreck';
const NAME = 'New York Times Bridge';
const URI = 'https://www.nytimes.com/';
const CACHE_TIMEOUT = 3600;
const CACHE_TIMEOUT = 900; // 15 minutes
const DESCRIPTION = 'RSS feed for the New York Times';

public function collectData(){
$this->collectExpandableDatas('https://rss.nytimes.com/services/xml/rss/nyt/HomePage.xml', 15);
$this->collectExpandableDatas('https://rss.nytimes.com/services/xml/rss/nyt/HomePage.xml', 40);
}

protected function parseItem($newsItem){
$item = parent::parseItem($newsItem);
$article = '';

// $articlePage gets the entire page's contents
$articlePage = getSimpleHTMLDOM($newsItem->link);

// handle subtitle
$subtitle = $articlePage->find('p.css-w6ymp8', 0);
if ($subtitle != null) {
$article .= '<strong>' . $subtitle->plaintext . '</strong>';
}

// figure contain's the main article image
$article = $articlePage->find('figure', 0);
// p > css-exrw3m has the actual article
foreach($articlePage->find('p.css-exrw3m') as $element)
$article = $article . $element;
$article .= $articlePage->find('figure', 0) . '<br />';

// section.meteredContent has the actual article
foreach($articlePage->find('section.meteredContent p') as $element)
$article .= '' . $element . '';

$item['content'] = $article;
return $item;
}
Expand Down

0 comments on commit 0de2db8

Please sign in to comment.