Skip to content

Commit

Permalink
fixed version number. Fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisbrownnwyc committed Jun 19, 2015
1 parent fddc67f commit f7727c7
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 18 deletions.
45 changes: 31 additions & 14 deletions imageresolver/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,19 @@ def __init__(self,**kwargs):
self.boost_png = kwargs.get('boost_png', 0)
self.skip_fetch_errors = kwargs.get('skip_fetch_errors',True)

self.abpy_black = None
self.abpy_white = None

if self.use_adblock_filters:
self.abpy_black = abpy.Filter(open(self.blacklist))
self.abpy_white = abpy.Filter(open(self.whitelist))
try:
self.abpy_black = abpy.Filter(open(self.blacklist))
except:
logger.warning('Unable to load black list file, %s.' % self.blacklist )

try:
self.abpy_white = abpy.Filter(open(self.whitelist))
except:
logger.warning('Unable to load white list file, %s.' % self.whitelist )

def _score(self,image):
score = 0
Expand Down Expand Up @@ -218,23 +228,30 @@ def _score(self,image):

if self.use_adblock_filters:
# just detect ads using AdBlockPlus filters (default)
black_matches = self.abpy_black.match(src)
try:
score = len(black_matches) * -1
except:
score = 0

no_filters = True
if self.abpy_black:
no_filters = False
black_matches = self.abpy_black.match(src)
try:
score = len(black_matches) * -1
except:
score = 0

white_matches = self.abpy_white.match(src)
if self.abpy_white:
no_filters = False
white_matches = self.abpy_white.match(src)

try:
score += len(white_matches)
except:
if not score:
score = 0
try:
score += len(white_matches)
except:
if not score:
score = 0

logger.debug('score set to ' + str(score) + ' using ABP filters')

if not self.use_js_ruleset and ( not self.use_adblock_filters or no_filters ):
logger.warning('No filters were enabled!')

return score

def resolve(self,url,**kwargs):
Expand Down
2 changes: 1 addition & 1 deletion imageresolver/abpy
Submodule abpy updated 2 files
+93 −88 abpy.py
+5 −109 abpy_singleMatch.py
11 changes: 8 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
from distutils.core import setup
from distutils.sysconfig import get_python_lib
import os
from imageresolver import __version__
import sys

# attempt to pull version
sys.path.append('./imageresolver')
from version import __version__

setup(
name='ImageResolver',
version=__version__,
author='Chris Brown',
author_email='[email protected]',
packages=['imageresolver','imageresolver.test','imageresolver.abpy'],
packages=['imageresolver','imageresolver.abpy'],
data_files=[(os.path.join( get_python_lib(),'imageresolver','data'),[ os.path.join('imageresolver','data','whitelist.txt') , os.path.join('imageresolver','data','blacklist.txt')])],
scripts=['bin/resolveimg.py'],
url='https://github.com/chrisbrownnwyc/ImageResolverPython',
url='https://github.com/constituentvoice/ImageResolverPython',
license='BSD',
description="Find the most significant image in an article.",
long_description=open('README.rst').read(),
install_requires=[ "requests >= 1.0.0","beautifulsoup4" ],
test_suite='tests'
)
File renamed without changes.
File renamed without changes.

0 comments on commit f7727c7

Please sign in to comment.