code-snippets

Some maybe useful snippets of code
git clone https://git.ortlepp.eu/code-snippets.git/
Log | Files | Refs | README

commit 1379278e12d755ffc063b8ae6fa8994cdf2f231a
parent a2d0723ea1e881ef524e9d4682169ffd1bbc5e35
Author: Thorsten Ortlepp <post@ortlepp.eu>
Date:   Sat, 23 May 2020 16:20:03 +0200

Added Tagesschau filter

Diffstat:
MREADME | 2+-
Aphp/rss-filter/tagesschau.php | 43+++++++++++++++++++++++++++++++++++++++++++
2 files changed, 44 insertions(+), 1 deletion(-)

diff --git a/README b/README @@ -24,4 +24,4 @@ PHP RSS filter ---------- -A script to remove unwanted articles from Heise Online RSS feed. +Two scripts to remove unwanted articles from Heise Online and Tagesschau RSS feeds. diff --git a/php/rss-filter/tagesschau.php b/php/rss-filter/tagesschau.php @@ -0,0 +1,43 @@ +<?php + +// A script to remove unwanted articles from Tagesschau RSS feed +// Code based on and inspired by https://github.com/fuzzy76/rssfilter/blob/master/rssfilter.php + +// Set proper MIME type and encoding +header('Content-Type: application/rss+xml; charset=utf-8'); + +// Process the original feed +$xml = simplexml_load_file('https://www.tagesschau.de/xml/rss2'); +$ix = 0; +while ($ix < count($xml->channel->item) ) { + if ( filter_title($xml->channel->item[$ix]->title) || filter_url($xml->channel->item[$ix]->link) ) { + unset($xml->channel->item[$ix]); + } else { + $ix++; + } +} +echo $xml->asXML(); + +// Filter by article title +function filter_title($title) { + if (strpos($title, 'Jetzt live') !== false) { + return true; + } + if (strpos($title, 'Live:') !== false) { + return true; + } + if (strpos($title, 'Liveblog') !== false) { + return true; + } + return false; +} + +// Filter by article URL +function filter_url($url) { + if (strpos($url, 'ardmediathek.de') !== false) { + return true; + } + return false; +} + +?>