crawler-user-agents 1.0.139 → 1.0.141

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.
@@ -31,6 +31,6 @@ jobs:
31
31
  with:
32
32
  python-version: '3.x'
33
33
  - run: pip install build
34
- - run: python -m build --sdist
34
+ - run: python -m build --wheel
35
35
  - name: Publish package
36
36
  uses: pypa/gh-action-pypi-publish@release/v1.8
package/README.md CHANGED
@@ -6,13 +6,15 @@ This repository contains a list of of HTTP user-agents used by robots, crawlers,
6
6
  * Go package: <https://pkg.go.dev/github.com/monperrus/crawler-user-agents>
7
7
  * PyPi package: <https://pypi.org/project/crawler-user-agents/>
8
8
 
9
+ Each `pattern` is a regular expression. It should work out-of-the-box wih your favorite regex library:
10
+
9
11
  ## Install
10
12
 
11
13
  ### Direct download
12
14
 
13
15
  Download the [`crawler-user-agents.json` file](https://raw.githubusercontent.com/monperrus/crawler-user-agents/master/crawler-user-agents.json) from this repository directly.
14
16
 
15
- ### Npm / Yarn
17
+ ### Javascript
16
18
 
17
19
  crawler-user-agents is deployed on npmjs.com: <https://www.npmjs.com/package/crawler-user-agents>
18
20
 
@@ -31,14 +33,21 @@ const crawlers = require('crawler-user-agents');
31
33
  console.log(crawlers);
32
34
  ```
33
35
 
34
- ## Usage
36
+ ### Python
35
37
 
36
- Each `pattern` is a regular expression. It should work out-of-the-box wih your favorite regex library:
38
+ Install with `pip install crawler-user-agents`
39
+
40
+ Then:
41
+
42
+ ```python
43
+ import crawleruseragents
44
+ if crawleruseragents.is_crawler("googlebot/"):
45
+ # do something
46
+ ```
47
+
48
+ ### Go
37
49
 
38
- * JavaScript: `if (RegExp(entry.pattern).test(req.headers['user-agent']) { ... }`
39
- * PHP: add a slash before and after the pattern: `if (preg_match('/'.$entry['pattern'].'/', $_SERVER['HTTP_USER_AGENT'])): ...`
40
- * Python: `if re.search(entry['pattern'], ua): ...`
41
- * Go: use [this package](https://pkg.go.dev/github.com/monperrus/crawler-user-agents),
50
+ Go: use [this package](https://pkg.go.dev/github.com/monperrus/crawler-user-agents),
42
51
  it provides global variable `Crawlers` (it is synchronized with `crawler-user-agents.json`),
43
52
  functions `IsCrawler` and `MatchingCrawlers`.
44
53
 
package/__init__.py ADDED
@@ -0,0 +1,22 @@
1
+ import crawleruseragents
2
+ import re
3
+ import json
4
+ from importlib import resources
5
+
6
+ def load_json():
7
+ return json.loads(resources.read_text(crawleruseragents,"crawler-user-agents.json"))
8
+
9
+ DATA = load_json()
10
+
11
+ def is_crawler(s):
12
+ # print(s)
13
+ for i in DATA:
14
+ test=re.search(i["pattern"],s,re.IGNORECASE)
15
+ if test:
16
+ return True
17
+ return False
18
+
19
+ def is_crawler2(s):
20
+ regexp = re.compile("|".join([i["pattern"] for i in DATA]))
21
+ return regexp.search(s) != None
22
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "crawler-user-agents",
3
- "version": "1.0.139",
3
+ "version": "1.0.141",
4
4
  "main": "crawler-user-agents.json",
5
5
  "typings": "./index.d.ts",
6
6
  "author": "Martin Monperrus <martin.monperrus@gnieh.org>",
package/pyproject.toml CHANGED
@@ -8,6 +8,8 @@ authors = [
8
8
 
9
9
  readme = "README.md"
10
10
 
11
- [tool.setuptools.packages.find]
12
- where = [ "." ]
11
+ [tool.setuptools]
12
+ package-dir = {"crawleruseragents" = "."}
13
13
 
14
+ [tool.setuptools.package-data]
15
+ "*" = ["*.json"]