summaryrefslogtreecommitdiff
path: root/main.py
diff options
context:
space:
mode:
authorssstvinc2 <sstvinc2@gmail.com>2017-03-23 08:35:22 -0400
committerssstvinc2 <sstvinc2@gmail.com>2017-03-23 08:35:22 -0400
commit80f76db4e9846ed809f1c1310615e6f36421c824 (patch)
tree2cec3f6d522cee8bba1490354edac7cfb1741f11 /main.py
parent449466e24998f5dedc8476e5391a0f932ebb0ec3 (diff)
reworked main loop to hopefully prevent crashing
Diffstat (limited to 'main.py')
-rwxr-xr-xmain.py63
1 files changed, 21 insertions, 42 deletions
diff --git a/main.py b/main.py
index 182ae26..c54487e 100755
--- a/main.py
+++ b/main.py
@@ -5,6 +5,7 @@ from unbiasedFunctions import *
from parser import *
import time
+
def main():
while True:
print('-----------------------')
@@ -23,49 +24,27 @@ def run():
'''
- #for some reason, The Guardian sometimes just doesn't work right?
- #loop until it gets it right
- '''
- h1='https://www.theguardian.com/us'
- looped=False
- while h1=='https://www.theguardian.com/us':
- try:
- gdn=buildGuardian()
- h1=gdn.h1Arr[0]
- except:
- print('The Guardian: build error. Looping again.')
- looped=True
- '''
- gdn=buildGuardian()
- sourceList.append(gdn)
-
- hil=buildTheHill()
- sourceList.append(hil)
-
- #nyt=buildNYT()
- #sourceList.append(nyt)
-
- npr=buildNPR()
- sourceList.append(npr)
- blz=buildBlaze()
- sourceList.append(blz)
-
- bbc=buildBBC()
- sourceList.append(bbc)
-
- nbc=buildNBC()
- sourceList.append(nbc)
-
- cbs=buildCBS()
- sourceList.append(cbs)
-
- #Weekly standard just doesn't update frequently enough
- #wkl=buildWeeklyStandard()
- #sourceList.append(wkl)
-
- fox=buildFoxNews()
- sourceList.append(fox)
+ ### These values have to be the second half of the function name
+ ### E.g. Guardian calls buildGuardian(), etc.
+ sourceFnArr=['Guardian', 'TheHill', 'NPR', 'Blaze', 'BBC', 'NBC', 'CBS',
+ 'FoxNews', ]
+
+ for source in sourceFnArr:
+ tries=0
+ while tries<3:
+ try:
+ fn='build'+source
+ possibles = globals().copy()
+ possibles.update(locals())
+ method = possibles.get(fn)
+ src=method()
+ sourceList.append(src)
+ break
+ except:
+ print('Build error. Looping again: '+source)
+ tries+=1
+ time.sleep(tries)
#scrape all urls and build data structure
newsSourceArr=buildNewsSourceArr(sourceList)