summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorssstvinc2 <sstvinc2@gmail.com>2017-02-12 22:10:40 -0500
committerssstvinc2 <sstvinc2@gmail.com>2017-02-12 22:10:40 -0500
commit1289131d2300bd991a2a2308d2a9396364c3fb62 (patch)
tree1095876c41ad0b6197369accb784ced79c96ea61
parent4dbd1edf115b04a9b149d46595753543ef7d6e23 (diff)
Increased # of secondary stories from 4 to 6
-rwxr-xr-xhtml_template/template.html2
-rw-r--r--unbiasedFunctions.py48
2 files changed, 26 insertions, 24 deletions
diff --git a/html_template/template.html b/html_template/template.html
index 071e1a4..ead234e 100755
--- a/html_template/template.html
+++ b/html_template/template.html
@@ -86,7 +86,6 @@
</div>
</a>
-<!--
<a target="_blank" href="xxURL2-5xx" >
<div class="middle-story">
<div class="middle-stories-img">
@@ -104,7 +103,6 @@
</div>
</div>
</a>
--->
</div>
diff --git a/unbiasedFunctions.py b/unbiasedFunctions.py
index e7ba4b4..da224ae 100644
--- a/unbiasedFunctions.py
+++ b/unbiasedFunctions.py
@@ -20,25 +20,29 @@ def buildArticle(url, sourceName):#, titleDelStart, titleDelEnd, imgDelStart, im
content=f.read()
f.close()
- #because the quote separator could be ' or ", trim to just before it then lop it off
- img=content.split('og:image" content=')[1][1:].split('>')[0]
- if img[-1]=='/':
- img=img[:-1].strip()
- img=img[:-1]
-
- title=content.split('og:title" content=')[1][1:].split('>')[0]
- if title[-1]=='/':
- title=title[:-1].strip()
- title=title[:-1]
-
- description=content.split('og:description" content=')[1][1:].split('>')[0]
- if description[-1]=='/':
- description=description[:-1].strip()
- description=description[:-1]
-
- a=Article(title, url, img, description, sourceName)
- return a
+ try:
+ #because the quote separator could be ' or ", trim to just before it then lop it off
+ img=content.split('og:image" content=')[1][1:].split('>')[0]
+ if img[-1]=='/':
+ img=img[:-1].strip()
+ img=img[:-1]
+
+ title=content.split('og:title" content=')[1][1:].split('>')[0]
+ if title[-1]=='/':
+ title=title[:-1].strip()
+ title=title[:-1]
+ description=content.split('og:description" content=')[1][1:].split('>')[0]
+ if description[-1]=='/':
+ description=description[:-1].strip()
+ description=description[:-1]
+
+ a=Article(title, url, img, description, sourceName)
+ return a
+
+ except:
+ print("Article parsing error in buildArticle() for URL: "+url)
+ return None
#do the hardcore HTML parsing
def splitHTML(content, sectionDividerStart, sectionDividerEnd, delStart, delEnd):
@@ -136,7 +140,7 @@ def buildOutput(newsSourceArr):
#set the random order for sources
h1RandomSources=random.sample(range(len(newsSourceArr)), 4)
- h2RandomSources=random.sample(range(len(newsSourceArr)), 4)
+ h2RandomSources=random.sample(range(len(newsSourceArr)), 6)
#replace html template locations with data from newsSourceArr
for i in range(len(h1RandomSources)):
@@ -208,13 +212,13 @@ def buildNewsSourceArr(sourceList):
if h1s!=None and h2s!=None:
for url in h1s:
article=buildArticle(url, source.name)
- source.addArticle(article, 1) #sourceList[i].h1Arr.append(article)
+ if article!=None: source.addArticle(article, 1) #sourceList[i].h1Arr.append(article)
for url in h2s:
article=buildArticle(url, source.name)
- sourceList[i].h2Arr.append(article)
+ if article!=None: sourceList[i].h2Arr.append(article)
for url in h3s:
article=buildArticle(url, source.name)
- sourceList[i].h3Arr.append(article)
+ if article!=None: sourceList[i].h3Arr.append(article)
i+=1
else:
sourceList.remove(source)