Skip to content

Commit

Permalink
new non interactive user agents support
Browse files Browse the repository at this point in the history
  • Loading branch information
joamag committed Nov 6, 2017
1 parent 28cc397 commit 12dd7d9
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 3 deletions.
12 changes: 12 additions & 0 deletions src/appier/defines.py
Expand Up @@ -89,6 +89,18 @@
identity = "Explorer",
sub_string = "MSIE",
version_search = "MSIE "
), dict(
identity = "Googlebot",
sub_string = "Googlebot",
interactive = False
), dict(
identity = "Bingbot",
sub_string = "Bingbot",
interactive = False
), dict(
identity = "DuckDuckBot",
sub_string = "DuckDuckBot",
interactive = False
)]
""" List that contains the complete information used
for the parsing and identification of the browser information
Expand Down
31 changes: 30 additions & 1 deletion src/appier/test/util.py
Expand Up @@ -97,6 +97,7 @@ def test_browser_info(self):
version = "12.10136",
version_f = 12.10136,
version_i = 12,
interactive = True,
os = "Windows"
))

Expand All @@ -106,6 +107,7 @@ def test_browser_info(self):
version = "62.0.3202.75",
version_f = 62.0,
version_i = 62,
interactive = True,
os = "Windows"
))

Expand All @@ -115,6 +117,7 @@ def test_browser_info(self):
version = "601.1",
version_f = 601.1,
version_i = 601,
interactive = True,
os = "Mac"
))

Expand All @@ -124,6 +127,7 @@ def test_browser_info(self):
version = "56.0",
version_f = 56.0,
version_i = 56,
interactive = True,
os = "Windows"
))

Expand All @@ -133,11 +137,36 @@ def test_browser_info(self):
version = "8.0",
version_f = 8.0,
version_i = 8,
interactive = True,
os = "Windows"
))

result = appier.browser_info("Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)")
self.assertEqual(result, None)
self.assertEqual(result, dict(
name = "Googlebot",
version = "2.1",
version_f = 2.1,
version_i = 2,
interactive = False
))

result = appier.browser_info("Mozilla/5.0 (compatible; Bingbot/2.0; +http://www.bing.com/bingbot.htm)")
self.assertEqual(result, dict(
name = "Bingbot",
version = "2.0",
version_f = 2.0,
version_i = 2,
interactive = False
))

result = appier.browser_info("DuckDuckBot/1.0; (+http://duckduckgo.com/duckduckbot.html)")
self.assertEqual(result, dict(
name = "DuckDuckBot",
version = "1.0",
version_f = 1.0,
version_i = 1,
interactive = False
))

result = appier.browser_info("APIs-Google (+https://developers.google.com/webmasters/APIs-Google.html)")
self.assertEqual(result, None)
Expand Down
10 changes: 8 additions & 2 deletions src/appier/util.py
Expand Up @@ -220,7 +220,11 @@ def is_browser(user_agent):
interactive browser or not.
"""

return True if browser_info(user_agent) else False
info = browser_info(user_agent)
if not info: return False
interactive = info.get("interactive", False)
if not interactive: return False
return True

def browser_info(user_agent):
info = dict()
Expand All @@ -229,6 +233,7 @@ def browser_info(user_agent):
identity = browser_i["identity"]
sub_string = browser_i.get("sub_string", identity)
version_search = browser_i.get("version_search", sub_string + "/")
interactive = browser_i.get("interactive", True)

if not sub_string in user_agent: continue
if not version_search in user_agent: continue
Expand All @@ -242,7 +247,8 @@ def browser_info(user_agent):
name = identity,
version = version,
version_f = version_f,
version_i = version_i
version_i = version_i,
interactive = interactive
)
break

Expand Down

0 comments on commit 12dd7d9

Please sign in to comment.