Skip to content

Commit

Permalink
[DagensNyheterDirektBridge] New bridge
Browse files Browse the repository at this point in the history
  • Loading branch information
ajain-93 committed Dec 15, 2023
1 parent 38e9c39 commit 11743f9
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions bridges/DagensNyheterDirektBridge.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?PHP
class DagensNyheterDirektBridge extends BridgeAbstract {

const NAME = 'Dagens Nyheter Direkt';
const URI = 'https://www.dn.se/direkt/';
const BASEURL = 'https://www.dn.se';
const DESCRIPTION = 'Latest news summarised by Dagens Nyheter';
const MAINTAINER = 'ajain-93';
const LIMIT = 20;

public function getIcon(){
return 'https://cdn.dn-static.se/images/favicon__c2dd3284b46ffdf4d520536e526065fa8.svg';
}

public function collectData(){

$NEWSURL = self::BASEURL . '/ajax/direkt/';

$html = getSimpleHTMLDOM($NEWSURL)
or returnServerError('Could not request: ' . $NEWSURL);

foreach($html->find('article') as $element) {

$link = $element->find('button', 0)->getAttribute('data-link');
$datetime = $element->getAttribute('data-publication-time');
$url = self::BASEURL . $link;
$title = $element->find('h2', 0)->plaintext;
$author = $element->find('div.ds-byline__titles', 0)->plaintext;
// Debug::log($link);
// Debug::log($datetime);
// Debug::log($title);
// Debug::log($url);
// Debug::log($author);

$article_content = $element->find('div.direkt-post__content', 0);
$article_html = '';

$figure = $element->find('figure', 0);
if ($figure) {
$article_html = $figure->find('img', 0) . '<p><i>' . $figure->find('figcaption', 0) . '</i></p>';
}

foreach($article_content->find('p') as $p) {
$article_html = $article_html . $p;
}

$item = array();
$item['uri'] = $url;
$item['title'] = $title;
$item['author'] = trim($author);
$item['timestamp'] = $datetime;
$item['content'] = trim($article_html);
$this->items[] = $item;

if (count($this->items) > self::LIMIT) {
break;
}
}
}
}

0 comments on commit 11743f9

Please sign in to comment.