From f19dd7a3291e2d61d4d76eef5300df522193fa1e Mon Sep 17 00:00:00 2001 From: sstvinc2 Date: Sat, 18 Feb 2017 17:10:13 -0600 Subject: Fixed NPR parsing; put NYT back in; Mobile CSS --- html_template/template.html | 1 + html_template/unbiased.css | 55 ++++++++++++++++++++++++++++++++++++++++++--- main.py | 12 ++++++++-- parser.py | 46 ++++++++++++++++++++++++------------- unbiasedFunctions.py | 1 + 5 files changed, 94 insertions(+), 21 deletions(-) diff --git a/html_template/template.html b/html_template/template.html index 1c2e858..c0e0711 100644 --- a/html_template/template.html +++ b/html_template/template.html @@ -1,6 +1,7 @@ + UnBiased diff --git a/html_template/unbiased.css b/html_template/unbiased.css index 52f1b66..126e194 100644 --- a/html_template/unbiased.css +++ b/html_template/unbiased.css @@ -19,8 +19,8 @@ a:link, a:visited, a:hover, a:active { text-align:center; padding:.5em 0 1em; margin-bottom:1em; - border-bottom:3px solid #f00; - background:#44a; + border-bottom:3px solid #BB133E; + background:#002147; } .title{ @@ -53,6 +53,12 @@ a:link, a:visited, a:hover, a:active { margin-right:auto; } +@media only screen and (max-width:900px){ + #page-container{ + width:100% + } +} + #top-stories{ width:95%; display:block; @@ -61,7 +67,7 @@ a:link, a:visited, a:hover, a:active { margin-left:auto; margin-right:auto; text-align:center; - border-bottom: 3px solid #f00; + border-bottom: 3px solid #BB133E; margin-bottom: 10px; } @@ -78,6 +84,14 @@ a:link, a:visited, a:hover, a:active { border:2px solid #ccc; } +@media only screen and (max-width:500px){ + .top-story{ + display:block; + width:auto; + height:auto; + } +} + .top-stories-img{ width:350px; height:200px; @@ -87,6 +101,13 @@ a:link, a:visited, a:hover, a:active { margin:0 auto; } +@media only screen and (max-width:500px){ + .top-stories-img{ + width:auto; + } +} + + .top-stories-hed{ font-weight:bold; font-size:1.35em; @@ -109,6 +130,13 @@ a:link, a:visited, a:hover, a:active { float:left; } +@media only screen and (max-width:500px){ + #middle-stories{ + width:100%; + float:none; + } +} + .middle-story{ margin:5px 10px; padding:10px; @@ -118,6 +146,12 @@ a:link, a:visited, a:hover, a:active { float:left; } +@media only screen and (max-width:500px){ + .middle-story{ + width:auto; + } +} + .middle-stories-img{ width:150px; height:100px; @@ -125,6 +159,7 @@ a:link, a:visited, a:hover, a:active { background-size: cover; background-position: center center; float:left; + max-width:35%; } .middle-stories-hed{ @@ -134,6 +169,12 @@ a:link, a:visited, a:hover, a:active { margin-left:10px; } +@media only screen and (max-width:500px){ + .middle-stories-hed{ + max-width:60%; + } +} + #bottom-stories{ margin:0 10px; padding:10px; @@ -144,6 +185,14 @@ a:link, a:visited, a:hover, a:active { border:5px solid #ddd; } +@media only screen and (max-width:900px){ + #bottom-stories{ + width:auto; + border-width:3px; + float:none; + } +} + .bottom-story{ padding:15px 0; } diff --git a/main.py b/main.py index 5025fdc..8318da0 100644 --- a/main.py +++ b/main.py @@ -15,9 +15,17 @@ def main(): def run(): sourceList=[] + ''' - #nyt=buildNYT() - #sourceList.append(nyt) + SOURCES TO ADD NEXT: + -ABC + -REUTERS + -THE HILL + + ''' + + nyt=buildNYT() + sourceList.append(nyt) npr=buildNPR() sourceList.append(npr) diff --git a/parser.py b/parser.py index 40532f7..5cb1c51 100644 --- a/parser.py +++ b/parser.py @@ -100,7 +100,7 @@ def removeDuplicates(h1s, h2s, h3s): -def removeBadStories(source, badTitleArr, badDescArr, badAuthorArr, badImgArr): +def removeBadStories(source, badTitleArr, badDescArr, badAuthorArr, badImgArr, badURLArr=None): arr=[source.h1Arr, source.h2Arr, source.h3Arr] @@ -159,6 +159,19 @@ def removeBadStories(source, badTitleArr, badDescArr, badAuthorArr, badImgArr): arr[1].remove(arr[1][0]) print('Removed:\n'+source.name+'\n'+hed.title+' from '+source.name+'\nReason: Image ('+item+')\n') + if badURLArr!=None: + for i in range(len(arr)): + for hed in arr[i]: + for item in badURLArr: + if item in hed.url: + arr[i].remove(hed) + #if it's in the h1 slot, bump up the + # first h2 into the h1 slot + if i==0: + arr[0].append(arr[1][0]) + arr[1].remove(arr[1][0]) + print('Removed:\n'+source.name+'\n'+hed.title+' from '+source.name+'\nReason: URL ('+item+')\n') + return source @@ -508,7 +521,7 @@ def buildWeeklyStandard(): badTitleArr=None ## if flagged again, remove Micah Mattix badDescArr=['Matt Labash'] - badAuthorArr=['MATT LABASH', 'TWS PODCAST', 'ERIC FELTEN', 'Steven J. Lenzner'] + badAuthorArr=['MATT LABASH', 'TWS PODCAST', 'ERIC FELTEN', 'Steven J. Lenzner', 'MARK HEMINGWAY'] badImgArr=['http://www.weeklystandard.com/s3/tws15/images/twitter/tws-twitter_1024x512.png'] wkl=removeBadStories(wkl, badTitleArr, badDescArr, badAuthorArr, badImgArr) @@ -518,7 +531,7 @@ def buildWeeklyStandard(): def buildNPR(): - url='http://npr.com' + url='http://www.npr.org/sections/news/' name='NPR' #DOWNLOAD HOMEPAGE CONTENT @@ -526,7 +539,7 @@ def buildNPR(): #get main headline h1=content - h1=h1.split('
', 1)[1] + h1=h1.split('', 1)[1] h1=h1.split('', 1)[1] - h2=h2.split('', 1)[0] - while 'href="' in h2: - h2=h2.split('href="', 1)[1] + h2=h2.split('