Skip to content

Commit f7727c7

Browse files
committed
fixed version number. Fixed tests
1 parent fddc67f commit f7727c7

File tree

5 files changed

+40
-18
lines changed

5 files changed

+40
-18
lines changed

imageresolver/__init__.py

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,19 @@ def __init__(self,**kwargs):
181181
self.boost_png = kwargs.get('boost_png', 0)
182182
self.skip_fetch_errors = kwargs.get('skip_fetch_errors',True)
183183

184+
self.abpy_black = None
185+
self.abpy_white = None
186+
184187
if self.use_adblock_filters:
185-
self.abpy_black = abpy.Filter(open(self.blacklist))
186-
self.abpy_white = abpy.Filter(open(self.whitelist))
188+
try:
189+
self.abpy_black = abpy.Filter(open(self.blacklist))
190+
except:
191+
logger.warning('Unable to load black list file, %s.' % self.blacklist )
192+
193+
try:
194+
self.abpy_white = abpy.Filter(open(self.whitelist))
195+
except:
196+
logger.warning('Unable to load white list file, %s.' % self.whitelist )
187197

188198
def _score(self,image):
189199
score = 0
@@ -218,23 +228,30 @@ def _score(self,image):
218228

219229
if self.use_adblock_filters:
220230
# just detect ads using AdBlockPlus filters (default)
221-
black_matches = self.abpy_black.match(src)
222-
try:
223-
score = len(black_matches) * -1
224-
except:
225-
score = 0
226-
231+
no_filters = True
232+
if self.abpy_black:
233+
no_filters = False
234+
black_matches = self.abpy_black.match(src)
235+
try:
236+
score = len(black_matches) * -1
237+
except:
238+
score = 0
227239

228-
white_matches = self.abpy_white.match(src)
240+
if self.abpy_white:
241+
no_filters = False
242+
white_matches = self.abpy_white.match(src)
229243

230-
try:
231-
score += len(white_matches)
232-
except:
233-
if not score:
234-
score = 0
244+
try:
245+
score += len(white_matches)
246+
except:
247+
if not score:
248+
score = 0
235249

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

252+
if not self.use_js_ruleset and ( not self.use_adblock_filters or no_filters ):
253+
logger.warning('No filters were enabled!')
254+
238255
return score
239256

240257
def resolve(self,url,**kwargs):

imageresolver/abpy

Submodule abpy updated from dd9b87e to a8ff334

setup.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
11
from distutils.core import setup
22
from distutils.sysconfig import get_python_lib
33
import os
4-
from imageresolver import __version__
4+
import sys
5+
6+
# attempt to pull version
7+
sys.path.append('./imageresolver')
8+
from version import __version__
59

610
setup(
711
name='ImageResolver',
812
version=__version__,
913
author='Chris Brown',
1014
author_email='[email protected]',
11-
packages=['imageresolver','imageresolver.test','imageresolver.abpy'],
15+
packages=['imageresolver','imageresolver.abpy'],
1216
data_files=[(os.path.join( get_python_lib(),'imageresolver','data'),[ os.path.join('imageresolver','data','whitelist.txt') , os.path.join('imageresolver','data','blacklist.txt')])],
1317
scripts=['bin/resolveimg.py'],
14-
url='https://github.com/chrisbrownnwyc/ImageResolverPython',
18+
url='https://github.com/constituentvoice/ImageResolverPython',
1519
license='BSD',
1620
description="Find the most significant image in an article.",
1721
long_description=open('README.rst').read(),
1822
install_requires=[ "requests >= 1.0.0","beautifulsoup4" ],
23+
test_suite='tests'
1924
)
File renamed without changes.

0 commit comments

Comments
 (0)