From: Nicolas Boisselier Date: Mon, 25 Jun 2018 13:43:03 +0000 (+0100) Subject: lib/php/mime.php X-Git-Url: https://git.nbdom.net/?a=commitdiff_plain;h=6ed31e711024bb4ab7e92d135e3840a83795e13e;p=nb.git lib/php/mime.php --- diff --git a/bin/rss-feedparser b/bin/rss-feedparser index 254e10f3..78667a09 100755 --- a/bin/rss-feedparser +++ b/bin/rss-feedparser @@ -5,6 +5,7 @@ import feedparser import time import datetime from dateutil import parser +import sys # Function to fetch the rss feed and return the parsed RSS def parseRSS( rss_url ): @@ -19,19 +20,30 @@ def getHeadlines( rss_url ): # NB 22.06.18 print(key) #print(feed['feed']['title']) #print(feed['items']) -# NB 23.06.18 for newsitem in feed['items']: -# NB 23.06.18 print() -# NB 23.06.18 for k,v in newsitem.items(): -# NB 23.06.18 print(k,' : ',v) -# NB 23.06.18 return +# NB 25.06.18 for newsitem in feed['items']: +# NB 25.06.18 print('>',feed['feed']['title']) +# NB 25.06.18 for k,v in newsitem.items(): +# NB 25.06.18 print(k) +# NB 25.06.18 #print(k,' : ',v) +# NB 25.06.18 break +# NB 25.06.18 return for newsitem in feed['items']: line = [ ] #headlines.append(newsitem['content'][0]['value'].replace("\n","")) #print(newsitem) - # Channel Title - line.append(feed['feed']['title']) + # Link + line.append(newsitem['link']) + + # Channel Link + line.append(re.sub('/*$','',feed['feed']['link'])) + + # Title + if 'title' in newsitem: + line.append(newsitem['title']) + else: + continue # Date if 'published_parsed' in newsitem: @@ -40,30 +52,27 @@ def getHeadlines( rss_url ): published = time.strftime('%F %T',newsitem["updated_parsed"]) else: continue - line.append(published) - # Title - if 'title' in newsitem: - line.append(newsitem['title']) - else: - continue - # Content content = '' if 'content' in newsitem: html = newsitem['content'][0]['value'] elif 'description' in newsitem: html = newsitem['description'] - elif 'link' in newsitem: - content = newsitem['link'] - #print(content) + elif 'comments' in newsitem: + html = newsitem['comments'] +# NB 25.06.18 elif 'link' in newsitem: +# NB 25.06.18 content = newsitem['link'] +# NB 25.06.18 #print(content) else: html = '' if not content: - soup = BeautifulSoup(html,"html.parser") - content = re.sub(r'\s*\n',' ',soup.get_text()) + content = html + #soup = BeautifulSoup(content,"html.parser") + #content = soup.get_text() + content = re.sub(r'\s*\n',' ',content) #content = soup.get_text().replace("\n"," ") line.append(content) @@ -73,16 +82,18 @@ def getHeadlines( rss_url ): return headlines -# A list to hold all headlines -allheadlines = [] - # List of RSS feeds that we will fetch and combine -urls = { +urls = [ #'https://feeds.feedburner.com/wrc/', + #'http://feeds.feedburner.com/CorbettReportRSS', #'https://www.egaliteetreconciliation.fr/spip.php?page=backend', - 'https://www.youtube.com/feeds/videos.xml?channel_id=UCUIjs9R044OjAxKzk0xhGoQ', -} + #'https://pressfortruth.ca/index.php/tools/blocks/problog_list/rss?cID=147', + #'https://www.infowars.com/feed/custom_feed_rss', + #'https://www.youtube.com/feeds/videos.xml?channel_id=UCUIjs9R044OjAxKzk0xhGoQ', +] -for url in urls: +for url in sys.argv[1:]: getHeadlines( url ) - +# NB 25.06.18 for url in urls: +# NB 25.06.18 getHeadlines( url ) +# NB 25.06.18 diff --git a/lib/php/mime.php b/lib/php/mime.php index d5127511..4b0af964 100644 --- a/lib/php/mime.php +++ b/lib/php/mime.php @@ -749,6 +749,7 @@ class Mime { .' frameborder="0"' .' allowfullscreen' .'>', + 'img' => function($str,$id) { return ''.htmlentities($str).''; }, ], 'youtube' => [ #'exp' => 'www.youtube.com/watch\?v=([^/&\s]+)', @@ -760,6 +761,7 @@ class Mime { .' frameborder="0"' .' allowfullscreen' .'>', + 'img' => function($str,$id) { return ''.htmlentities($str).''; }, ], ]; @@ -767,15 +769,23 @@ class Mime { if (!preg_match(','.$site['exp'].',',$str,$m)) continue; $id = $m[1]; $idsite = $k; + + if (!empty($site['img'])) { + $fct = $site['img']; + $img = $fct($str,$id); + } + break; } if (empty($id)) { + $ext = preg_match(',^(\w+://|/).*\.(\w+)$,',$str,$m) ? $m[2] : ''; if ($ext) foreach (self::Types as $t => $e) { if (strpos($t,'video/') !== 0 or $e != $ext) continue; return '