Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
This repository was archived by the owner on Dec 26, 2023. It is now read-only.

Commit d9cc2b3

Browse filesBrowse files
committed
Renamed 'is_spider' property to 'is_bot'.
1 parent 2a2852d commit d9cc2b3
Copy full SHA for d9cc2b3

File tree

Expand file treeCollapse file tree

3 files changed

+35
-24
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+35
-24
lines changed

‎README.rst

Copy file name to clipboardExpand all lines: README.rst
+15-4Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Python User Agents
22
==================
33

4-
``user_agents`` is a Python library that provides an easy way to identify devices like mobile phones,
5-
tablets and their capabilities by parsing (browser) user agent strings. The goal is to reliably
4+
``user_agents`` is a Python library that provides an easy way to identify/detect devices like mobile
5+
phones, tablets and their capabilities by parsing (browser) user agent strings. The goal is to reliably
66
detect whether:
77

88
* User agent is a mobile, tablet or PC based device
@@ -12,7 +12,7 @@ detect whether:
1212
actual parsing of the raw user agent string.
1313

1414
This library should be considered "alpha". Please post feature suggestions, bug or pull requests to
15-
identify more devices on Github.
15+
identify more devices on `Github <https://github.com/selwin/python-user-agents>`_
1616

1717

1818
Installation
@@ -26,7 +26,7 @@ WARNING: This library should be considered "alpha". Use this in production at yo
2626
pip install pyyaml ua-parser user-agents
2727

2828
Alternatively, you can also get the latest source code from
29-
`Github <https://github.com/selwin/python-user-agents>`_ and install it manually.
29+
`Github`_ and install it manually.
3030

3131
Usage
3232
=====
@@ -69,6 +69,7 @@ Currently these attributes are supported:
6969
* ``is_tablet``: whether user agent is identified as a tablet device (iPad, Kindle Fire, Nexus 7 etc)
7070
* ``is_pc``: whether user agent is identified to be running a traditional "desktop" OS (Windows, OS X, Linux)
7171
* ``is_touch_capable``: whether user agent has touch capabilities
72+
* ``is_bot``: whether user agent is a search engine crawler/spider
7273

7374

7475
For example:
@@ -84,6 +85,7 @@ For example:
8485
user_agent.is_tablet # returns False
8586
user_agent.is_touch_capable # returns False
8687
user_agent.is_pc # returns False
88+
user_agent.is_bot # returns False
8789
8890
# Now a Samsung Galaxy S3
8991
ua_string = 'Mozilla/5.0 (Linux; U; Android 4.0.4; en-gb; GT-I9300 Build/IMM76D) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30'
@@ -92,6 +94,7 @@ For example:
9294
user_agent.is_tablet # returns False
9395
user_agent.is_touch_capable # returns True
9496
user_agent.is_pc # returns False
97+
user_agent.is_bot # returns False
9598
9699
# iPad's user agent string
97100
ua_string = 'Mozilla/5.0(iPad; U; CPU iPhone OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B314 Safari/531.21.10'
@@ -100,6 +103,7 @@ For example:
100103
user_agent.is_tablet # returns True
101104
user_agent.is_touch_capable # returns True
102105
user_agent.is_pc # returns False
106+
user_agent.is_bot # returns False
103107
104108
# Kindle Fire's user agent string
105109
ua_string = 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_3; en-us; Silk/1.1.0-80) AppleWebKit/533.16 (KHTML, like Gecko) Version/5.0 Safari/533.16 Silk-Accelerated=true'
@@ -108,6 +112,7 @@ For example:
108112
user_agent.is_tablet # returns True
109113
user_agent.is_touch_capable # returns True
110114
user_agent.is_pc # returns False
115+
user_agent.is_bot # returns False
111116
112117
# Touch capable Windows 8 device
113118
ua_string = 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Trident/6.0; Touch)'
@@ -116,6 +121,7 @@ For example:
116121
user_agent.is_tablet # returns False
117122
user_agent.is_touch_capable # returns True
118123
user_agent.is_pc # returns True
124+
user_agent.is_bot # returns False
119125
120126
121127
Running Tests
@@ -127,6 +133,11 @@ Running Tests
127133
Changelog
128134
=========
129135

136+
Version 0.1.1
137+
-------------
138+
* Added ``is_bot`` property
139+
* Symbian OS devices are now detected as a mobile device
140+
130141
Version 0.1
131142
-----------
132143
* Initial release

‎user_agents/parsers.py

Copy file name to clipboardExpand all lines: user_agents/parsers.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ def is_pc(self):
167167
return False
168168

169169
@property
170-
def is_spider(self):
170+
def is_bot(self):
171171
return True if self.device.family == 'Spider' else False
172172

173173

‎user_agents/tests.py

Copy file name to clipboardExpand all lines: user_agents/tests.py
+19-19Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -151,22 +151,22 @@ def test_is_pc(self):
151151
self.assertTrue(ie_touch_ua.is_pc)
152152
self.assertTrue(ie_ua.is_pc)
153153

154-
def test_is_spider(self):
155-
self.assertTrue(google_bot_ua.is_spider)
156-
self.assertFalse(iphone_ua.is_spider)
157-
self.assertFalse(galaxy_s3_ua.is_spider)
158-
self.assertFalse(ipad_ua.is_spider)
159-
self.assertFalse(playbook_ua.is_spider)
160-
self.assertFalse(kindle_fire_ua.is_spider)
161-
self.assertFalse(nexus_7_ua.is_spider)
162-
self.assertFalse(windows_phone_ua.is_spider)
163-
self.assertFalse(blackberry_bold_touch_ua.is_spider)
164-
self.assertFalse(blackberry_torch_ua.is_spider)
165-
self.assertFalse(blackberry_bold_ua.is_spider)
166-
self.assertFalse(j2me_opera_ua.is_spider)
167-
self.assertFalse(mac_safari_ua.is_spider)
168-
self.assertFalse(windows_ie_ua.is_spider)
169-
self.assertFalse(ubuntu_firefox_ua.is_spider)
170-
self.assertFalse(ie_touch_ua.is_spider)
171-
self.assertFalse(ie_ua.is_spider)
172-
self.assertFalse(nokia_n97_ua.is_spider)
154+
def test_is_bot(self):
155+
self.assertTrue(google_bot_ua.is_bot)
156+
self.assertFalse(iphone_ua.is_bot)
157+
self.assertFalse(galaxy_s3_ua.is_bot)
158+
self.assertFalse(ipad_ua.is_bot)
159+
self.assertFalse(playbook_ua.is_bot)
160+
self.assertFalse(kindle_fire_ua.is_bot)
161+
self.assertFalse(nexus_7_ua.is_bot)
162+
self.assertFalse(windows_phone_ua.is_bot)
163+
self.assertFalse(blackberry_bold_touch_ua.is_bot)
164+
self.assertFalse(blackberry_torch_ua.is_bot)
165+
self.assertFalse(blackberry_bold_ua.is_bot)
166+
self.assertFalse(j2me_opera_ua.is_bot)
167+
self.assertFalse(mac_safari_ua.is_bot)
168+
self.assertFalse(windows_ie_ua.is_bot)
169+
self.assertFalse(ubuntu_firefox_ua.is_bot)
170+
self.assertFalse(ie_touch_ua.is_bot)
171+
self.assertFalse(ie_ua.is_bot)
172+
self.assertFalse(nokia_n97_ua.is_bot)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.