summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore4
-rw-r--r--setup.py20
-rw-r--r--unbiased/__init__.py0
-rwxr-xr-xunbiased/main.py19
-rwxr-xr-xunbiased/parser.py5
-rwxr-xr-xunbiased/spotCheck.py6
-rw-r--r--unbiased/unbiasedFunctions.py28
7 files changed, 57 insertions, 25 deletions
diff --git a/.gitignore b/.gitignore
index 90bf98d..238da47 100644
--- a/.gitignore
+++ b/.gitignore
@@ -6,5 +6,9 @@ legacy_py/
unbiased.html
html_template/Penguins.jpg
html_template/BAK*
+build/
+dist/
+venv/
+unbiased.egg-info/
#*
.#*
diff --git a/setup.py b/setup.py
new file mode 100644
index 0000000..8b73e6d
--- /dev/null
+++ b/setup.py
@@ -0,0 +1,20 @@
+from setuptools import setup
+
+setup(
+ name="unbiased",
+ version="0",
+ packages=['unbiased'],
+ package_data={
+ 'unbiased': [
+ 'html_template/*.html',
+ 'html_template/*.css',
+ ],
+ },
+ install_requires=[
+ ],
+ entry_points={
+ 'console_scripts': [
+ 'unbiased = unbiased.main:main',
+ ],
+ },
+)
diff --git a/unbiased/__init__.py b/unbiased/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/unbiased/__init__.py
diff --git a/unbiased/main.py b/unbiased/main.py
index f1c3317..b8bd4cb 100755
--- a/unbiased/main.py
+++ b/unbiased/main.py
@@ -1,26 +1,26 @@
#!/usr/bin/env python3
import argparse
-import os
-
-from unbiasedObjects import *
-from unbiasedFunctions import *
-from parser import *
import time
+from unbiased.unbiasedObjects import *
+from unbiased.unbiasedFunctions import *
+from unbiased.parser import *
+
def main():
parser = argparse.ArgumentParser()
parser.add_argument('-w', '--webroot', default='/var/www/ubiased', help='location to write the output html')
+ parser.add_argument('-s', '--scratch', default='/opt/unbiased/scratch', help='writable scratch workspace')
args = parser.parse_args()
while True:
print('-----------------------')
- run(args.webroot)
+ run(args.webroot, args.scratch)
print('-----------------------')
time.sleep(600)
-def run(webroot):
+def run(webroot, scratch):
sourceList=[]
'''
@@ -33,6 +33,7 @@ def run(webroot):
'''
print('running with webroot="{}"'.format(webroot))
+ print('running with scratch="{}"'.format(scratch))
### These values have to be the second half of the function name
@@ -51,7 +52,7 @@ def run(webroot):
src=method()
sourceList.append(src)
break
- except:
+ except Exception:
print('Build error. Looping again: '+source)
tries+=1
time.sleep(tries)
@@ -63,7 +64,7 @@ def run(webroot):
outputHTML=buildOutput(newsSourceArr)
#print the output file HTML
- printOutputHTML(outputHTML, os.path.join(webroot, 'index.html'))
+ printOutputHTML(outputHTML, webroot)
if __name__=="__main__":
diff --git a/unbiased/parser.py b/unbiased/parser.py
index f69281b..1f9bc5c 100755
--- a/unbiased/parser.py
+++ b/unbiased/parser.py
@@ -1,10 +1,11 @@
#!/usr/bin/env python3
-from unbiasedObjects import *
-from unbiasedFunctions import buildArticle
import os
import re
+from unbiased.unbiasedObjects import *
+from unbiased.unbiasedFunctions import buildArticle
+
'''
Takes in a URL, downloads the file to a temp file,
diff --git a/unbiased/spotCheck.py b/unbiased/spotCheck.py
index d1edda4..7ce50d3 100755
--- a/unbiased/spotCheck.py
+++ b/unbiased/spotCheck.py
@@ -1,10 +1,10 @@
#!/usr/bin/env python3
-
-from parser import *
-from unbiasedObjects import *
import sys
+from unbiased.parser import *
+from unbiased.unbiasedObjects import *
+
def spotCheck(src):
fns = {'hil' : buildTheHill,
diff --git a/unbiased/unbiasedFunctions.py b/unbiased/unbiasedFunctions.py
index 1a80d7a..3d3363b 100644
--- a/unbiased/unbiasedFunctions.py
+++ b/unbiased/unbiasedFunctions.py
@@ -1,8 +1,10 @@
-from unbiasedObjects import *
import os
+import pkgutil
import random
-import time
import re
+import time
+
+from unbiased.unbiasedObjects import *
#take in a url and delimiters, return twitter card
@@ -110,7 +112,7 @@ def buildArticle(url, sourceName, encoding=None):#, titleDelStart, titleDelEnd,
a=Article(title, url, img, description, sourceName, author)
return a
- except:
+ except Exception:
print('^^^^^^^^^^^^^^^^^^^^^^^^^')
print('\tARTICLE PARSING ERROR')
print('SOURCE: '+sourceName)
@@ -121,9 +123,8 @@ def buildArticle(url, sourceName, encoding=None):#, titleDelStart, titleDelEnd,
def buildOutput(newsSourceArr):
#read in the template html file
- f=open('html_template/template.html', 'r')
- template=f.read()
- f.close()
+ template=pkgutil.get_data('unbiased', 'html_template/template.html')
+ template = template.decode('utf8')
#set the random order for sources
h1RandomSources=[]
@@ -201,13 +202,18 @@ def buildOutput(newsSourceArr):
#return updated text
return template
-def printOutputHTML(outputHTML, outFile):
+def printOutputHTML(outputHTML, outDir):
timestamp=time.strftime("%a, %b %-d, %-I:%M%P %Z", time.localtime())
outputHTML=outputHTML.replace('xxTimexx', timestamp)
-
- f=open(outFile, 'w')
- f.write(outputHTML)
- f.close()
+
+ with open(os.path.join(outDir, 'index.html'), 'w') as fp:
+ fp.write(outputHTML)
+
+ # copy over the template css file
+ css = pkgutil.get_data('unbiased', 'html_template/unbiased.css')
+ css = css.decode('utf8')
+ with open(os.path.join(outDir, 'unbiased.css'), 'w') as fp:
+ fp.write(css)
def buildNewsSourceArr(sourceList):