summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--unbiased/unbiasedFunctions.py5
-rw-r--r--unbiased/unbiasedObjects.py5
2 files changed, 9 insertions, 1 deletions
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():