aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Arnav Jain <ajain-93@users.noreply.github.com> 2023-12-15 23:36:50 +0100
committerGravatar GitHub <noreply@github.com> 2023-12-15 23:36:50 +0100
commitd127bf6e009318914f9b35222fcd97ff137dad57 (patch)
treec320f090d951eec092749db5a3d33c8f8c4debcb
parent38e9c396cfe6b933f1752942385dcf5ee05730d6 (diff)
downloadrss-bridge-d127bf6e009318914f9b35222fcd97ff137dad57.tar.gz
rss-bridge-d127bf6e009318914f9b35222fcd97ff137dad57.tar.zst
rss-bridge-d127bf6e009318914f9b35222fcd97ff137dad57.zip
[DagensNyheterDirektBridge] New bridge (#3834)
* [DagensNyheterDirektBridge] New bridge * [DagensNyheterDirektBridge] Lint: Replace all tabs with space * [DagensNyheterDirektBridge] Lint: Lines Add empty lines and move start brace to new line * [DagensNyheterDirektBridge] Lint: short- array syntax * [DagensNyheterDirektBridge] Lint: short array syntax Fix incorrect line ending * [DagensNyheterDirektBridge] Lint: further lint fixes * [DagensNyheterDirektBridge] Lint: final fixes
-rw-r--r--bridges/DagensNyheterDirektBridge.php62
1 files changed, 62 insertions, 0 deletions
diff --git a/bridges/DagensNyheterDirektBridge.php b/bridges/DagensNyheterDirektBridge.php
new file mode 100644
index 00000000..4d1629fb
--- /dev/null
+++ b/bridges/DagensNyheterDirektBridge.php
@@ -0,0 +1,62 @@
+<?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;
+ }
+
+ $this->items[] = [
+ 'uri' => $url,
+ 'title' => $title,
+ 'author' => trim($author),
+ 'timestamp' => $datetime,
+ 'content' => trim($article_html),
+ ];
+
+ if (count($this->items) > self::LIMIT) {
+ break;
+ }
+ }
+ }
+}