Skip to content

Commit

Permalink
Introduced a basic path blacklist
Browse files Browse the repository at this point in the history
  • Loading branch information
palewire committed Jul 28, 2014
1 parent d744b83 commit 76641ac
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
15 changes: 14 additions & 1 deletion storysniffer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,26 @@
re.IGNORECASE
)

# A list of URL paths tha probably won't link to new stories
PATH_BLACKLIST = (
'',
'/',
)


def guess(url):
"""
Returns a boolean estimating the likelihood that
the provided URL links to a news story.
"""
# Throw an error if the URL doesn't match acceptable patterns
if not URL_REGEX.search(url):
raise ValueError("Provided url does not match acceptable URL patterns")

urlparse(url)
urlparts = urlparse(url)

if urlparts.path in PATH_BLACKLIST:
return False

# If you've it this far, return True
return True
4 changes: 4 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ def test_busted(self):
with self.assertRaises(ValueError):
storysniffer.guess(self.busted)

def test_guess(self):
self.assertTrue(storysniffer.guess(self.yes))
self.assertFalse(storysniffer.guess(self.no))


if __name__ == '__main__':
if six.PY3:
Expand Down

0 comments on commit 76641ac

Please sign in to comment.