uaid 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- uaid/__init__.py +24 -0
- uaid/py.typed +0 -0
- uaid/rules.json +1 -0
- uaid-0.1.0.dist-info/METADATA +47 -0
- uaid-0.1.0.dist-info/RECORD +7 -0
- uaid-0.1.0.dist-info/WHEEL +4 -0
- uaid-0.1.0.dist-info/licenses/LICENSE +201 -0
uaid/__init__.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import json
|
|
2
|
+
from importlib.resources import files
|
|
3
|
+
|
|
4
|
+
data = json.loads(files(__package__).joinpath("rules.json").read_text())
|
|
5
|
+
keywords = (
|
|
6
|
+
"bot crawl spider http .com url @ check site headless preview scan scrap fetch "
|
|
7
|
+
"monitor index feed inspect resolver google- -google ptst"
|
|
8
|
+
).split()
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def identify(user_agent: str) -> dict | None:
|
|
12
|
+
lowered = "^" + user_agent.lower()
|
|
13
|
+
for first, rest, index in data["rules"]:
|
|
14
|
+
if first in lowered and all(part in lowered for part in rest):
|
|
15
|
+
return data["crawlers"][index]
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def looks_like_bot(user_agent: str) -> bool:
|
|
19
|
+
lowered = user_agent.lower()
|
|
20
|
+
return "(" not in lowered or any(word in lowered for word in keywords)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def is_bot(user_agent: str) -> bool:
|
|
24
|
+
return looks_like_bot(user_agent) or identify(user_agent) is not None
|
uaid/py.typed
ADDED
|
File without changes
|