Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Commit

Permalink
Prevent duplicated feeds in additionalChannels
Browse files Browse the repository at this point in the history
  • Loading branch information
Victor Beek committed May 10, 2018
1 parent 11114c2 commit 6e14457
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions nederland24.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@
["NPO Event 3", "npo_placeholder.png", "LI_NEDERLAND3_221713", "NPO Evenementkanaal 3."],
]


class Feed(object):
def __init__(self, title, url, img):
self.title = title
self.url = url
self.image = img


def index():
for channel in CHANNELS:
if settings.getSetting(channel[0]) == 'true':
Expand Down Expand Up @@ -169,22 +177,24 @@ def addLink(name, url, mode, iconimage, description):
return ok


def additionalChannels(url, depth):
def additionalChannels(feed_url, depth):
i = 0
URL = url
# URL = 'http://feeds.nos.nl/journaal'
items = SoupStrainer('item')
for tag in BeautifulStoneSoup(urllib2.urlopen(URL).read(), parseOnlyThese=items):
items_to_add = [] # Create a list of distinct items to display
for tag in BeautifulStoneSoup(urllib2.urlopen(feed_url).read(), parseOnlyThese=items):
try:
title = tag.title.contents[0]
url = tag.find('media:content')['url']
tag_url = tag.find('media:content')['url']
img = os.path.join(IMG_DIR, "npo_placeholder.png")
addLink(title, url, "playVideo", img, '')
i += 1
if not any(tag_url == item.url for item in items_to_add):
items_to_add.append(Feed(title, tag_url, img))
i += 1
if i == int(depth):
break
except (AttributeError): # Prevent error when there are no additional channels available
except AttributeError: # Prevent error when there are no additional channels available
break
for item in items_to_add:
addLink(item.title, item.url, "playVideo", item.image, '')


def playVideo(url):
Expand Down

0 comments on commit 6e14457

Please sign in to comment.