From 2236cc2bfd5d78f8efd0cd31e2c5737a78b06b5d Mon Sep 17 00:00:00 2001 From: Matt Singleton Date: Sun, 3 Sep 2017 14:10:54 -0400 Subject: some niceties for debugging --- unbiased/unbiasedFunctions.py | 5 +++++ unbiased/unbiasedObjects.py | 5 ++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/unbiased/unbiasedFunctions.py b/unbiased/unbiasedFunctions.py index cb13a44..6ec89b7 100644 --- a/unbiased/unbiasedFunctions.py +++ b/unbiased/unbiasedFunctions.py @@ -142,8 +142,10 @@ def buildArticle(url, sourceName, encoding=None):#, titleDelStart, titleDelEnd, def pickStories(newsSourceArr): + # TODO: refactor to avoid infinite loops #set the random order for sources h1RandomSources=[] + guard = 0 while len(h1RandomSources)<4: x=random.sample(range(len(newsSourceArr)), 1)[0] if len(newsSourceArr[x].h1Arr)>0: @@ -151,6 +153,9 @@ def pickStories(newsSourceArr): h1RandomSources.append(x) else: logger.debug('No H1 stories in '+newsSourceArr[x].name) + guard += 1 + if guard > 100: + return [], [], [] #For h2s and h3s, select N random sources (can repeat), then #a non-repetitive random article from within diff --git a/unbiased/unbiasedObjects.py b/unbiased/unbiasedObjects.py index 7908fbb..9a8a78a 100644 --- a/unbiased/unbiasedObjects.py +++ b/unbiased/unbiasedObjects.py @@ -19,7 +19,10 @@ class Article(): self.author=author def __str__(self): - return '-----------\n'+self.title+'\n'+self.author+'\n'+self.source+'\n'+self.description+'\n'+self.url+'\n'+self.img+'\n'+'-----------' + return '-----------\ntitle: {}\nauthor: {}\nsource: {}\ndescription: {}\nurl: {}\nimg: {}\n-----------'.format(self.title, self.author, self.source, self.description, self.url, self.img) + + def __repr__(self): + return '{}({}, {}, {})'.format(self.source.replace(' ', ''), self.title, self.author, self.url) class NewsSource2(): -- cgit v1.2.3