diff options
author | Matt Singleton <matt@xcolour.net> | 2017-09-03 14:10:54 -0400 |
---|---|---|
committer | Matt Singleton <matt@xcolour.net> | 2017-09-03 14:10:54 -0400 |
commit | 2236cc2bfd5d78f8efd0cd31e2c5737a78b06b5d (patch) | |
tree | 4e8ab8f23ee1782f745b88048178e3d0b6067e2f | |
parent | 924e6e0ece7ef9e85cfe761c5383a54000dad2f7 (diff) |
some niceties for debugging
-rw-r--r-- | unbiased/unbiasedFunctions.py | 5 | ||||
-rw-r--r-- | unbiased/unbiasedObjects.py | 5 |
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():
|