ayugespidertools 3.1.0__tar.gz → 3.2.0__tar.gz

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.
Files changed (92) hide show
  1. {ayugespidertools-3.1.0 → ayugespidertools-3.2.0}/PKG-INFO +7 -8
  2. {ayugespidertools-3.1.0 → ayugespidertools-3.2.0}/README.md +5 -5
  3. {ayugespidertools-3.1.0 → ayugespidertools-3.2.0}/ayugespidertools/common/encryption.py +1 -1
  4. {ayugespidertools-3.1.0 → ayugespidertools-3.2.0}/ayugespidertools/common/expend.py +1 -1
  5. {ayugespidertools-3.1.0 → ayugespidertools-3.2.0}/ayugespidertools/common/mongodbpipe.py +3 -37
  6. {ayugespidertools-3.1.0 → ayugespidertools-3.2.0}/ayugespidertools/common/multiplexing.py +13 -6
  7. {ayugespidertools-3.1.0 → ayugespidertools-3.2.0}/ayugespidertools/common/mysqlerrhandle.py +1 -8
  8. ayugespidertools-3.2.0/ayugespidertools/common/spiderconf.py +183 -0
  9. {ayugespidertools-3.1.0 → ayugespidertools-3.2.0}/ayugespidertools/common/sqlformat.py +1 -1
  10. {ayugespidertools-3.1.0 → ayugespidertools-3.2.0}/ayugespidertools/common/typevars.py +32 -8
  11. {ayugespidertools-3.1.0 → ayugespidertools-3.2.0}/ayugespidertools/common/utils.py +9 -2
  12. {ayugespidertools-3.1.0 → ayugespidertools-3.2.0}/ayugespidertools/common/yidungap.py +1 -1
  13. {ayugespidertools-3.1.0 → ayugespidertools-3.2.0}/ayugespidertools/config.py +1 -6
  14. {ayugespidertools-3.1.0 → ayugespidertools-3.2.0}/ayugespidertools/formatdata.py +1 -1
  15. {ayugespidertools-3.1.0 → ayugespidertools-3.2.0}/ayugespidertools/imgoperation.py +1 -1
  16. {ayugespidertools-3.1.0 → ayugespidertools-3.2.0}/ayugespidertools/middlewares.py +0 -4
  17. {ayugespidertools-3.1.0 → ayugespidertools-3.2.0}/ayugespidertools/mongoclient.py +1 -1
  18. {ayugespidertools-3.1.0 → ayugespidertools-3.2.0}/ayugespidertools/mysqlclient.py +1 -1
  19. {ayugespidertools-3.1.0 → ayugespidertools-3.2.0}/ayugespidertools/oss.py +1 -1
  20. {ayugespidertools-3.1.0 → ayugespidertools-3.2.0}/ayugespidertools/pipelines.py +2 -0
  21. {ayugespidertools-3.1.0 → ayugespidertools-3.2.0}/ayugespidertools/scraper/middlewares/__init__.py +0 -4
  22. {ayugespidertools-3.1.0 → ayugespidertools-3.2.0}/ayugespidertools/scraper/middlewares/headers/ua.py +1 -1
  23. {ayugespidertools-3.1.0 → ayugespidertools-3.2.0}/ayugespidertools/scraper/middlewares/netlib/__init__.py +0 -4
  24. {ayugespidertools-3.1.0 → ayugespidertools-3.2.0}/ayugespidertools/scraper/middlewares/netlib/aiohttplib.py +2 -3
  25. {ayugespidertools-3.1.0 → ayugespidertools-3.2.0}/ayugespidertools/scraper/middlewares/proxy/dynamic.py +11 -18
  26. ayugespidertools-3.2.0/ayugespidertools/scraper/middlewares/proxy/exclusive.py +67 -0
  27. {ayugespidertools-3.1.0 → ayugespidertools-3.2.0}/ayugespidertools/scraper/pipelines/mongo/asynced.py +1 -17
  28. {ayugespidertools-3.1.0 → ayugespidertools-3.2.0}/ayugespidertools/scraper/pipelines/mongo/fantasy.py +1 -21
  29. {ayugespidertools-3.1.0 → ayugespidertools-3.2.0}/ayugespidertools/scraper/pipelines/mongo/twisted.py +0 -1
  30. ayugespidertools-3.2.0/ayugespidertools/scraper/pipelines/msgproducer/kafkapub.py +104 -0
  31. ayugespidertools-3.2.0/ayugespidertools/scraper/pipelines/msgproducer/mqpub.py +55 -0
  32. {ayugespidertools-3.1.0 → ayugespidertools-3.2.0}/ayugespidertools/scraper/pipelines/mysql/__init__.py +1 -25
  33. {ayugespidertools-3.1.0 → ayugespidertools-3.2.0}/ayugespidertools/scraper/pipelines/mysql/asynced.py +116 -117
  34. {ayugespidertools-3.1.0 → ayugespidertools-3.2.0}/ayugespidertools/scraper/pipelines/mysql/turbo.py +0 -2
  35. {ayugespidertools-3.1.0 → ayugespidertools-3.2.0}/ayugespidertools/scraper/pipelines/mysql/twisted.py +1 -2
  36. {ayugespidertools-3.1.0 → ayugespidertools-3.2.0}/ayugespidertools/scraper/spiders/__init__.py +216 -192
  37. {ayugespidertools-3.1.0 → ayugespidertools-3.2.0}/ayugespidertools/templates/project/module/VIT/.conf +5 -0
  38. {ayugespidertools-3.1.0 → ayugespidertools-3.2.0}/ayugespidertools/templates/spiders/basic.tmpl +1 -5
  39. {ayugespidertools-3.1.0 → ayugespidertools-3.2.0}/ayugespidertools/templates/spiders/crawl.tmpl +0 -2
  40. {ayugespidertools-3.1.0 → ayugespidertools-3.2.0}/pyproject.toml +2 -3
  41. ayugespidertools-3.1.0/ayugespidertools/common/spiderdbconf.py +0 -115
  42. ayugespidertools-3.1.0/ayugespidertools/processmanager.py +0 -1
  43. ayugespidertools-3.1.0/ayugespidertools/rpa.py +0 -74
  44. ayugespidertools-3.1.0/ayugespidertools/runjs.py +0 -32
  45. ayugespidertools-3.1.0/ayugespidertools/scraper/middlewares/netlib/requestslib.py +0 -108
  46. ayugespidertools-3.1.0/ayugespidertools/scraper/middlewares/proxy/exclusive.py +0 -74
  47. ayugespidertools-3.1.0/ayugespidertools/scraper/pipelines/msgproducer/mqpub.py +0 -88
  48. ayugespidertools-3.1.0/ayugespidertools/templates/project/.gitignore +0 -139
  49. {ayugespidertools-3.1.0 → ayugespidertools-3.2.0}/LICENSE +0 -0
  50. {ayugespidertools-3.1.0 → ayugespidertools-3.2.0}/ayugespidertools/__init__.py +0 -0
  51. {ayugespidertools-3.1.0 → ayugespidertools-3.2.0}/ayugespidertools/commands/__init__.py +0 -0
  52. {ayugespidertools-3.1.0 → ayugespidertools-3.2.0}/ayugespidertools/commands/crawl.py +0 -0
  53. {ayugespidertools-3.1.0 → ayugespidertools-3.2.0}/ayugespidertools/commands/genspider.py +0 -0
  54. {ayugespidertools-3.1.0 → ayugespidertools-3.2.0}/ayugespidertools/commands/startproject.py +0 -0
  55. {ayugespidertools-3.1.0 → ayugespidertools-3.2.0}/ayugespidertools/commands/version.py +0 -0
  56. {ayugespidertools-3.1.0 → ayugespidertools-3.2.0}/ayugespidertools/common/__init__.py +0 -0
  57. {ayugespidertools-3.1.0 → ayugespidertools-3.2.0}/ayugespidertools/common/params.py +0 -0
  58. {ayugespidertools-3.1.0 → ayugespidertools-3.2.0}/ayugespidertools/items.py +0 -0
  59. {ayugespidertools-3.1.0 → ayugespidertools-3.2.0}/ayugespidertools/request.py +0 -0
  60. {ayugespidertools-3.1.0 → ayugespidertools-3.2.0}/ayugespidertools/scraper/__init__.py +0 -0
  61. {ayugespidertools-3.1.0 → ayugespidertools-3.2.0}/ayugespidertools/scraper/http/__init__.py +0 -0
  62. {ayugespidertools-3.1.0 → ayugespidertools-3.2.0}/ayugespidertools/scraper/http/request/__init__.py +0 -0
  63. {ayugespidertools-3.1.0 → ayugespidertools-3.2.0}/ayugespidertools/scraper/http/request/form.py +0 -0
  64. {ayugespidertools-3.1.0 → ayugespidertools-3.2.0}/ayugespidertools/scraper/middlewares/proxy/__init__.py +0 -0
  65. {ayugespidertools-3.1.0 → ayugespidertools-3.2.0}/ayugespidertools/scraper/middlewares/proxy/private.py +0 -0
  66. {ayugespidertools-3.1.0 → ayugespidertools-3.2.0}/ayugespidertools/scraper/pipelines/__init__.py +0 -0
  67. {ayugespidertools-3.1.0 → ayugespidertools-3.2.0}/ayugespidertools/scraper/pipelines/download/file.py +0 -0
  68. {ayugespidertools-3.1.0 → ayugespidertools-3.2.0}/ayugespidertools/scraper/pipelines/download/image.py +0 -0
  69. {ayugespidertools-3.1.0 → ayugespidertools-3.2.0}/ayugespidertools/scraper/pipelines/mongo/__init__.py +0 -0
  70. {ayugespidertools-3.1.0 → ayugespidertools-3.2.0}/ayugespidertools/scraper/pipelines/msgproducer/__init__.py +0 -0
  71. {ayugespidertools-3.1.0 → ayugespidertools-3.2.0}/ayugespidertools/scraper/pipelines/mysql/fantasy.py +0 -0
  72. {ayugespidertools-3.1.0 → ayugespidertools-3.2.0}/ayugespidertools/scraper/pipelines/mysql/stats.py +0 -0
  73. {ayugespidertools-3.1.0 → ayugespidertools-3.2.0}/ayugespidertools/scraper/spiders/crawl.py +0 -0
  74. {ayugespidertools-3.1.0 → ayugespidertools-3.2.0}/ayugespidertools/spiders.py +0 -0
  75. {ayugespidertools-3.1.0 → ayugespidertools-3.2.0}/ayugespidertools/templates/project/README.md +0 -0
  76. {ayugespidertools-3.1.0 → ayugespidertools-3.2.0}/ayugespidertools/templates/project/module/__init__.py +0 -0
  77. {ayugespidertools-3.1.0 → ayugespidertools-3.2.0}/ayugespidertools/templates/project/module/items.py.tmpl +0 -0
  78. {ayugespidertools-3.1.0 → ayugespidertools-3.2.0}/ayugespidertools/templates/project/module/middlewares.py.tmpl +0 -0
  79. {ayugespidertools-3.1.0 → ayugespidertools-3.2.0}/ayugespidertools/templates/project/module/pipelines.py.tmpl +0 -0
  80. {ayugespidertools-3.1.0 → ayugespidertools-3.2.0}/ayugespidertools/templates/project/module/run.py.tmpl +0 -0
  81. {ayugespidertools-3.1.0 → ayugespidertools-3.2.0}/ayugespidertools/templates/project/module/run.sh.tmpl +0 -0
  82. {ayugespidertools-3.1.0 → ayugespidertools-3.2.0}/ayugespidertools/templates/project/module/settings.py.tmpl +0 -0
  83. {ayugespidertools-3.1.0 → ayugespidertools-3.2.0}/ayugespidertools/templates/project/module/spiders/__init__.py +0 -0
  84. {ayugespidertools-3.1.0 → ayugespidertools-3.2.0}/ayugespidertools/templates/project/pyproject.toml +0 -0
  85. {ayugespidertools-3.1.0 → ayugespidertools-3.2.0}/ayugespidertools/templates/project/requirements.txt +0 -0
  86. {ayugespidertools-3.1.0 → ayugespidertools-3.2.0}/ayugespidertools/templates/project/scrapy.cfg +0 -0
  87. {ayugespidertools-3.1.0 → ayugespidertools-3.2.0}/ayugespidertools/templates/spiders/async.tmpl +0 -0
  88. {ayugespidertools-3.1.0 → ayugespidertools-3.2.0}/ayugespidertools/templates/spiders/csvfeed.tmpl +0 -0
  89. {ayugespidertools-3.1.0 → ayugespidertools-3.2.0}/ayugespidertools/templates/spiders/xmlfeed.tmpl +0 -0
  90. {ayugespidertools-3.1.0 → ayugespidertools-3.2.0}/ayugespidertools/utils/__init__.py +0 -0
  91. {ayugespidertools-3.1.0 → ayugespidertools-3.2.0}/ayugespidertools/utils/cmdline.py +0 -0
  92. {ayugespidertools-3.1.0 → ayugespidertools-3.2.0}/ayugespidertools/verificationcode.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ayugespidertools
3
- Version: 3.1.0
3
+ Version: 3.2.0
4
4
  Summary: scrapy 扩展库:用于扩展 Scrapy 功能来解放双手,还内置一些爬虫开发中的通用方法。
5
5
  Home-page: https://www.ayuge.top/mkdocs-material/
6
6
  Keywords: crawler,scraping,twisted,aiohttp,asyncio,scrapy,aiomysql,mmh3
@@ -15,7 +15,6 @@ Classifier: Programming Language :: Python :: 3.10
15
15
  Classifier: Programming Language :: Python :: 3.11
16
16
  Requires-Dist: DBUtils (>=3.0.2,<4.0.0)
17
17
  Requires-Dist: Pillow (>=9.2.0,<10.0.0)
18
- Requires-Dist: PyExecJS (>=1.5.1,<2.0.0)
19
18
  Requires-Dist: PyMySQL (>=1.0.2,<2.0.0)
20
19
  Requires-Dist: SQLAlchemy (>=1.4.41,<2.0.0)
21
20
  Requires-Dist: Scrapy (==2.9.0)
@@ -23,9 +22,9 @@ Requires-Dist: WorkWeixinRobot (>=1.0.1,<2.0.0)
23
22
  Requires-Dist: aiohttp (>=3.8.3,<4.0.0)
24
23
  Requires-Dist: aiomysql (>=0.1.1,<0.2.0)
25
24
  Requires-Dist: attrs (>=22.2.0,<23.0.0)
26
- Requires-Dist: environs (>=9.5.0,<10.0.0)
27
25
  Requires-Dist: html2text (>=2020.1.16,<2021.0.0)
28
26
  Requires-Dist: itemadapter (>=0.7.0,<0.8.0)
27
+ Requires-Dist: kafka-python (==2.0.2)
29
28
  Requires-Dist: loguru (>=0.6.0,<0.7.0)
30
29
  Requires-Dist: mmh3 (>=3.0.0,<4.0.0)
31
30
  Requires-Dist: motor (==2.5.1)
@@ -137,8 +136,7 @@ scrapy crawl <spider_name>
137
136
 
138
137
  # 将 `Scrapy` 的 `Request`,`FormRequest` 替换为其它工具实现的场景
139
138
  - 以上为使用 scrapy Request 的场景
140
- + 7).demo_seven: scrapy Request 替换为 requests 请求的场景(一般情况下不推荐使用,同步库
141
- + 会拖慢 scrapy 速度,可用于测试场景)
139
+ - 7).demo_seven: scrapy Request 替换为 requests 请求的场景(已删除此功能,更推荐使用 aiohttp 方式)
142
140
 
143
141
  + 8).demo_eight: 同时存入 Mysql 和 MongoDB 的场景
144
142
 
@@ -156,7 +154,8 @@ scrapy crawl <spider_name>
156
154
  -16).demo_item_loader_two: 展示本库使用 itemLoader 特性的示例,此示例已删除,可查看上个 demo_item_loader 中的示例,目前已经可以很方便的使用 Item Loaders 功能了
157
155
 
158
156
  +17).demo_mongo_async: asyncio 版本存储 mongoDB 的 pipelines 示例
159
- +18).demo_mq: 数据存入 rabbitmq 的模板示例,通过 pika 库实现
157
+ +18).demo_mq: 数据存入 rabbitmq 的模板示例
158
+ +19).demo_kafka: 数据存入 rabbitmq 的模板示例
160
159
  ```
161
160
 
162
161
  注:具体内容及时效性请以 [DemoSpider](https://github.com/shengchenyang/DemoSpider) 项目中描述为准。
@@ -219,7 +218,7 @@ scrapy crawl <spider_name>
219
218
  - [x] 代理中间件(独享代理、动态隧道代理)
220
219
  - [x] 随机请求头 `UA` 中间件,根据 `fake_useragent` 中的权重来随机
221
220
  - [x] 使用以下工具来替换 `scrapy` 的 `Request` 来发送请求
222
- - [x] `requests`: 这个不推荐使用,`requests` 同步库会降低 `scrapy` 运行效率
221
+ - [x] ~~`requests`: 这个不推荐使用,`requests` 同步库会降低 `scrapy` 运行效率~~(已移除此功能,更推荐 `aiohttp` 的方式)
223
222
  - [x] `aiohttp`: 集成将 `scrapy Request` 替换为 `aiohttp` 的协程方式
224
223
  - [x] `Mysql` 存储的场景下适配
225
224
  - [x] 自动创建 `Mysql` 用户场景下需要的数据库和数据表及字段格式,还有字段注释
@@ -227,7 +226,7 @@ scrapy crawl <spider_name>
227
226
  - [x] `asyncio` 语法支持与 `async` 第三方库支持示例
228
227
  - [x] `spider` 中使用 `asyncio` 的 `aiohttp` 示例
229
228
  - [x] `pipeline` 中使用 `asyncio` 的 `aioMysql` 示例
230
- - [ ] 集成 `Kafka`,`RabbitMQ` 等数据推送功能
229
+ - [x] 集成 `Kafka`,`RabbitMQ` 等数据推送功能
231
230
  - [x] 常用开发场景
232
231
  - [x] `sql` 语句拼接,只是简单场景,后续优化。已给出优化方向,参考库等信息。
233
232
  - [x] `mongoDB` 语句拼接
@@ -90,8 +90,7 @@ scrapy crawl <spider_name>
90
90
 
91
91
  # 将 `Scrapy` 的 `Request`,`FormRequest` 替换为其它工具实现的场景
92
92
  - 以上为使用 scrapy Request 的场景
93
- + 7).demo_seven: scrapy Request 替换为 requests 请求的场景(一般情况下不推荐使用,同步库
94
- + 会拖慢 scrapy 速度,可用于测试场景)
93
+ - 7).demo_seven: scrapy Request 替换为 requests 请求的场景(已删除此功能,更推荐使用 aiohttp 方式)
95
94
 
96
95
  + 8).demo_eight: 同时存入 Mysql 和 MongoDB 的场景
97
96
 
@@ -109,7 +108,8 @@ scrapy crawl <spider_name>
109
108
  -16).demo_item_loader_two: 展示本库使用 itemLoader 特性的示例,此示例已删除,可查看上个 demo_item_loader 中的示例,目前已经可以很方便的使用 Item Loaders 功能了
110
109
 
111
110
  +17).demo_mongo_async: asyncio 版本存储 mongoDB 的 pipelines 示例
112
- +18).demo_mq: 数据存入 rabbitmq 的模板示例,通过 pika 库实现
111
+ +18).demo_mq: 数据存入 rabbitmq 的模板示例
112
+ +19).demo_kafka: 数据存入 rabbitmq 的模板示例
113
113
  ```
114
114
 
115
115
  注:具体内容及时效性请以 [DemoSpider](https://github.com/shengchenyang/DemoSpider) 项目中描述为准。
@@ -172,7 +172,7 @@ scrapy crawl <spider_name>
172
172
  - [x] 代理中间件(独享代理、动态隧道代理)
173
173
  - [x] 随机请求头 `UA` 中间件,根据 `fake_useragent` 中的权重来随机
174
174
  - [x] 使用以下工具来替换 `scrapy` 的 `Request` 来发送请求
175
- - [x] `requests`: 这个不推荐使用,`requests` 同步库会降低 `scrapy` 运行效率
175
+ - [x] ~~`requests`: 这个不推荐使用,`requests` 同步库会降低 `scrapy` 运行效率~~(已移除此功能,更推荐 `aiohttp` 的方式)
176
176
  - [x] `aiohttp`: 集成将 `scrapy Request` 替换为 `aiohttp` 的协程方式
177
177
  - [x] `Mysql` 存储的场景下适配
178
178
  - [x] 自动创建 `Mysql` 用户场景下需要的数据库和数据表及字段格式,还有字段注释
@@ -180,7 +180,7 @@ scrapy crawl <spider_name>
180
180
  - [x] `asyncio` 语法支持与 `async` 第三方库支持示例
181
181
  - [x] `spider` 中使用 `asyncio` 的 `aiohttp` 示例
182
182
  - [x] `pipeline` 中使用 `asyncio` 的 `aioMysql` 示例
183
- - [ ] 集成 `Kafka`,`RabbitMQ` 等数据推送功能
183
+ - [x] 集成 `Kafka`,`RabbitMQ` 等数据推送功能
184
184
  - [x] 常用开发场景
185
185
  - [x] `sql` 语句拼接,只是简单场景,后续优化。已给出优化方向,参考库等信息。
186
186
  - [x] `mongoDB` 语句拼接
@@ -12,7 +12,7 @@ __all__ = [
12
12
  ]
13
13
 
14
14
 
15
- class EncryptOperation(object):
15
+ class EncryptOperation:
16
16
  """
17
17
  普通加密方法
18
18
  """
@@ -13,7 +13,7 @@ __all__ = [
13
13
  ]
14
14
 
15
15
 
16
- class MysqlPipeEnhanceMixin(object):
16
+ class MysqlPipeEnhanceMixin:
17
17
  """
18
18
  用于扩展 pipelines 中的功能,作为 Mixin 使用,不要对其实例化和单独使用等
19
19
  """
@@ -19,24 +19,6 @@ class AbstractClass(ABC):
19
19
  用于处理 mongodb pipeline 存储的模板方法类
20
20
  """
21
21
 
22
- def _get_collection_name(self, table: str, collection_prefix: str = "") -> str:
23
- """
24
- 获取集合名称
25
- Args:
26
- table: item 中的 table 字段
27
- collection_prefix: 集合前缀
28
-
29
- Returns:
30
- full_collection_name: 完整的集合名称
31
- """
32
- assert isinstance(table, str), "item 中 table 字段不是 str,或未传入 table 参数"
33
- full_collection_name = f"""{collection_prefix}{table}"""
34
-
35
- assert (
36
- " " not in full_collection_name
37
- ), "集合名不能含空格,请检查 MONGODB_COLLECTION_PREFIX 参数和 item 中的 table 参数"
38
- return full_collection_name
39
-
40
22
  def _get_insert_data(
41
23
  self,
42
24
  item_dict: Union[ItemAdapter, dict],
@@ -64,28 +46,21 @@ class AbstractClass(ABC):
64
46
  self,
65
47
  item_dict: Union[ItemAdapter, dict],
66
48
  db: Param.PymongoDataBase,
67
- collection_prefix: str = "",
68
49
  ) -> None:
69
50
  """
70
51
  模板方法,用于处理 mongodb pipeline 存储的模板方法类
71
52
  Args:
72
53
  item_dict: item ItemAdapter 或 dict 格式数据
73
54
  db: mongodb 数据库连接
74
- collection_prefix: 集合前缀
75
55
 
76
56
  Returns:
77
57
  None
78
58
  """
79
59
  insert_data = self._get_insert_data(item_dict)
80
- # 真实的集合名称为:集合前缀名 + 集合名称
81
- collection_name = self._get_collection_name(
82
- table=item_dict["_table"],
83
- collection_prefix=collection_prefix,
84
- )
85
60
  self._data_storage_logic(
86
61
  db=db,
87
62
  item_dict=item_dict,
88
- collection_name=collection_name,
63
+ collection_name=item_dict["_table"],
89
64
  insert_data=insert_data,
90
65
  )
91
66
 
@@ -185,18 +160,12 @@ class AsyncioAsynchronous(AbstractClass):
185
160
  self,
186
161
  item_dict: Union[ItemAdapter, dict],
187
162
  db: Param.PymongoDataBase,
188
- collection_prefix: str = "",
189
163
  ) -> None:
190
164
  insert_data = self._get_insert_data(item_dict)
191
- # 真实的集合名称为:集合前缀名 + 集合名称
192
- collection_name = self._get_collection_name(
193
- table=item_dict["_table"],
194
- collection_prefix=collection_prefix,
195
- )
196
165
  await self._data_storage_logic(
197
166
  db=db,
198
167
  item_dict=item_dict,
199
- collection_name=collection_name,
168
+ collection_name=item_dict["_table"],
200
169
  insert_data=insert_data,
201
170
  )
202
171
 
@@ -205,11 +174,8 @@ def mongodb_pipe(
205
174
  abstract_class: AbstractClass,
206
175
  item_dict: Union[ItemAdapter, dict],
207
176
  db: Param.PymongoDataBase,
208
- collection_prefix: str = "",
209
177
  ) -> None:
210
178
  """
211
179
  mongodb pipeline 存储的通用调用方法
212
180
  """
213
- abstract_class.process_item_template(
214
- item_dict=item_dict, db=db, collection_prefix=collection_prefix
215
- )
181
+ abstract_class.process_item_template(item_dict=item_dict, db=db)
@@ -20,7 +20,7 @@ __all__ = [
20
20
  ]
21
21
 
22
22
 
23
- class ReuseOperation(object):
23
+ class ReuseOperation:
24
24
  """
25
25
  用于存放经常复用的一些操作
26
26
  """
@@ -52,18 +52,16 @@ class ReuseOperation(object):
52
52
  config_parser = configparser.ConfigParser()
53
53
  config_parser.read(f"{vit_dir}/.conf", encoding="utf-8")
54
54
  # Mysql 数据库配置
55
- inner_settings["LOCAL_MYSQL_CONFIG"] = {
55
+ inner_settings["MYSQL_CONFIG"] = {
56
56
  "host": config_parser.get("mysql", "host", fallback=None),
57
57
  "port": config_parser.getint("mysql", "port", fallback=3306),
58
58
  "user": config_parser.get("mysql", "user", fallback="root"),
59
59
  "password": config_parser.get("mysql", "password", fallback=None),
60
60
  "charset": config_parser.get("mysql", "charset", fallback="utf8mb4"),
61
61
  "database": config_parser.get("mysql", "database", fallback=None),
62
- # 数据库 engin 采用的驱动,可不填此参数
63
- "driver": "mysqlconnector",
64
62
  }
65
63
  # MongoDB 数据库配置
66
- inner_settings["LOCAL_MONGODB_CONFIG"] = {
64
+ inner_settings["MONGODB_CONFIG"] = {
67
65
  "host": config_parser.get("mongodb", "host", fallback=None),
68
66
  "port": config_parser.getint("mongodb", "port", fallback=27017),
69
67
  "authsource": config_parser.get("mongodb", "authsource", fallback="admin"),
@@ -115,6 +113,8 @@ class ReuseOperation(object):
115
113
  "username": config_parser.get("mq", "username", fallback="guest"),
116
114
  "password": config_parser.get("mq", "password", fallback="guest"),
117
115
  "virtualhost": config_parser.get("mq", "virtualhost", fallback="/"),
116
+ "heartbeat": config_parser.getint("mq", "heartbeat", fallback=0),
117
+ "socket_timeout": config_parser.getint("mq", "socket_timeout", fallback=1),
118
118
  "queue": config_parser.get("mq", "queue", fallback=None),
119
119
  "durable": config_parser.getboolean("mq", "durable", fallback=True),
120
120
  "exclusive": config_parser.getboolean("mq", "exclusive", fallback=False),
@@ -129,6 +129,14 @@ class ReuseOperation(object):
129
129
  "delivery_mode": config_parser.getint("mq", "delivery_mode", fallback=1),
130
130
  "mandatory": config_parser.getboolean("mq", "mandatory", fallback=True),
131
131
  }
132
+ # kafka 配置
133
+ inner_settings["KAFKA_CONFIG"] = {
134
+ "bootstrap_servers": config_parser.get(
135
+ "kafka", "bootstrap_servers", fallback="127.0.0.1:9092"
136
+ ),
137
+ "topic": config_parser.get("kafka", "topic", fallback=None),
138
+ "key": config_parser.get("kafka", "key", fallback=None),
139
+ }
132
140
  return inner_settings
133
141
 
134
142
  @staticmethod
@@ -217,7 +225,6 @@ class ReuseOperation(object):
217
225
  else:
218
226
  # 0 表示采用黑白的方式读取图片
219
227
  tp_cv = cv2.imread(tp, 0)
220
-
221
228
  return bg_cv, tp_cv
222
229
 
223
230
  @staticmethod
@@ -111,7 +111,6 @@ class AbstractClass(ABC):
111
111
  collate: str,
112
112
  database: str,
113
113
  table: str,
114
- table_prefix: str,
115
114
  table_enum: Type[TableEnumTypeVar],
116
115
  note_dic: dict,
117
116
  ) -> None:
@@ -125,7 +124,6 @@ class AbstractClass(ABC):
125
124
  collate: mysql table collate
126
125
  database: 数据库
127
126
  table: 数据表
128
- table_prefix: 数据表前缀
129
127
  table_enum: 数据表枚举类
130
128
  note_dic: 当前表字段注释
131
129
 
@@ -141,7 +139,6 @@ class AbstractClass(ABC):
141
139
  elif "1146" in err_msg:
142
140
  table_name, table_notes, demand_code = self.deal_1146_error(
143
141
  err_msg=err_msg,
144
- table_prefix=table_prefix,
145
142
  table_enum=table_enum,
146
143
  )
147
144
  self._create_table(
@@ -205,14 +202,12 @@ class AbstractClass(ABC):
205
202
  def deal_1146_error(
206
203
  self,
207
204
  err_msg: str,
208
- table_prefix: str,
209
205
  table_enum: Type[TableEnumTypeVar],
210
206
  ) -> (str, str, str):
211
207
  """
212
208
  解决 1146, u"Table '(.*?)' doesn't exist"
213
209
  Args:
214
210
  err_msg: 报错内容
215
- table_prefix: 数据表前缀
216
211
  table_enum: 数据表的枚举信息
217
212
 
218
213
  Returns:
@@ -227,7 +222,7 @@ class AbstractClass(ABC):
227
222
  # 写入表枚举
228
223
  if table_enum:
229
224
  for _, member in table_enum.__members__.items():
230
- table_name = f'{table_prefix}{member.value.get("value", "")}'
225
+ table_name = member.value.get("value", "")
231
226
  table_notes = member.value.get("notes", "")
232
227
  demand_code = member.value.get("demand_code", "")
233
228
  if table_name == table:
@@ -378,7 +373,6 @@ def deal_mysql_err(
378
373
  collate: str,
379
374
  database: str,
380
375
  table: str,
381
- table_prefix: str,
382
376
  table_enum: Type[TableEnumTypeVar],
383
377
  note_dic: dict,
384
378
  conn: Optional[Param.PymysqlConnect] = None,
@@ -391,7 +385,6 @@ def deal_mysql_err(
391
385
  collate,
392
386
  database,
393
387
  table,
394
- table_prefix,
395
388
  table_enum,
396
389
  note_dic,
397
390
  )
@@ -0,0 +1,183 @@
1
+ from abc import ABC, abstractmethod
2
+ from typing import TypeVar, Union
3
+
4
+ from scrapy.settings import Settings
5
+
6
+ from ayugespidertools.common.typevars import (
7
+ DynamicProxyConf,
8
+ ExclusiveProxyConf,
9
+ KafkaConf,
10
+ MongoDBConf,
11
+ MQConf,
12
+ MysqlConf,
13
+ )
14
+ from ayugespidertools.common.utils import ToolsForAyu
15
+
16
+ __all__ = [
17
+ "get_spider_conf",
18
+ "MysqlConfCreator",
19
+ "MongoDBConfCreator",
20
+ "MQConfCreator",
21
+ "KafkaConfCreator",
22
+ "DynamicProxyCreator",
23
+ "ExclusiveProxyCreator",
24
+ ]
25
+
26
+ SpiderConf = TypeVar(
27
+ "SpiderConf",
28
+ MysqlConf,
29
+ MongoDBConf,
30
+ MQConf,
31
+ KafkaConf,
32
+ DynamicProxyConf,
33
+ ExclusiveProxyConf,
34
+ )
35
+
36
+
37
+ class Product(ABC):
38
+ @abstractmethod
39
+ def get_conn_conf(self) -> Union[SpiderConf, None]:
40
+ """
41
+ 获取各个工具链接配置信息
42
+ """
43
+ pass
44
+
45
+
46
+ class Creator(ABC):
47
+ @abstractmethod
48
+ def create_product(self, *args, **kwargs) -> Product:
49
+ pass
50
+
51
+
52
+ class MysqlConfProduct(Product):
53
+ def __init__(self, settings: Settings, consul_conf: dict):
54
+ self._settings = settings
55
+ self._consul_conf = consul_conf
56
+
57
+ def get_conn_conf(self) -> Union[MysqlConf, None]:
58
+ # 1). 优先从 consul 中取值
59
+ if _ := self._settings.get("APP_CONF_MANAGE", False):
60
+ consul_conf = ToolsForAyu.get_conf_by_consul(
61
+ conf_name="mysql", **self._consul_conf
62
+ )
63
+ return MysqlConf(**consul_conf) if consul_conf else None
64
+
65
+ # 2). 从本地参数中取值
66
+ local_conf = self._settings.get("MYSQL_CONFIG")
67
+ return MysqlConf(**local_conf) if local_conf else None
68
+
69
+
70
+ class MongoDBConfProduct(Product):
71
+ def __init__(self, settings, consul_conf):
72
+ self._settings = settings
73
+ self._consul_conf = consul_conf
74
+
75
+ def get_conn_conf(self) -> Union[MongoDBConf, None]:
76
+ if _ := self._settings.get("APP_CONF_MANAGE", False):
77
+ consul_conf = ToolsForAyu.get_conf_by_consul(
78
+ conf_name="mongodb", **self._consul_conf
79
+ )
80
+ return MongoDBConf(**consul_conf) if consul_conf else None
81
+
82
+ local_conf = self._settings.get("MONGODB_CONFIG")
83
+ return MongoDBConf(**local_conf) if local_conf else None
84
+
85
+
86
+ class MQConfProduct(Product):
87
+ def __init__(self, settings, consul_conf):
88
+ self._settings = settings
89
+ self._consul_conf = consul_conf
90
+
91
+ def get_conn_conf(self) -> Union[MQConf, None]:
92
+ if _ := self._settings.get("APP_CONF_MANAGE", False):
93
+ consul_conf = ToolsForAyu.get_conf_by_consul(
94
+ conf_name="rabbitmq", **self._consul_conf
95
+ )
96
+ return MQConf(**consul_conf) if consul_conf else None
97
+
98
+ local_conf = self._settings.get("MQ_CONFIG")
99
+ return MQConf(**local_conf) if local_conf else None
100
+
101
+
102
+ class KafkaConfProduct(Product):
103
+ def __init__(self, settings, consul_conf):
104
+ self._settings = settings
105
+ self._consul_conf = consul_conf
106
+
107
+ def get_conn_conf(self) -> Union[KafkaConf, None]:
108
+ if _ := self._settings.get("APP_CONF_MANAGE", False):
109
+ consul_conf = ToolsForAyu.get_conf_by_consul(
110
+ conf_name="kafka", **self._consul_conf
111
+ )
112
+ return KafkaConf(**consul_conf) if consul_conf else None
113
+
114
+ local_conf = self._settings.get("KAFKA_CONFIG")
115
+ return KafkaConf(**local_conf) if local_conf else None
116
+
117
+
118
+ class DynamicProxyProduct(Product):
119
+ def __init__(self, settings, consul_conf):
120
+ self._settings = settings
121
+ self._consul_conf = consul_conf
122
+
123
+ def get_conn_conf(self) -> Union[DynamicProxyConf, None]:
124
+ if _ := self._settings.get("APP_CONF_MANAGE", False):
125
+ consul_conf = ToolsForAyu.get_conf_by_consul(
126
+ conf_name="dynamicproxy", **self._consul_conf
127
+ )
128
+ return DynamicProxyConf(**consul_conf) if consul_conf else None
129
+
130
+ local_conf = self._settings.get("DYNAMIC_PROXY_CONFIG")
131
+ return DynamicProxyConf(**local_conf) if local_conf else None
132
+
133
+
134
+ class ExclusiveProxyProduct(Product):
135
+ def __init__(self, settings, consul_conf):
136
+ self._settings = settings
137
+ self._consul_conf = consul_conf
138
+
139
+ def get_conn_conf(self) -> Union[ExclusiveProxyConf, None]:
140
+ if _ := self._settings.get("APP_CONF_MANAGE", False):
141
+ consul_conf = ToolsForAyu.get_conf_by_consul(
142
+ conf_name="exclusiveproxy", **self._consul_conf
143
+ )
144
+ return ExclusiveProxyConf(**consul_conf) if consul_conf else None
145
+
146
+ local_conf = self._settings.get("EXCLUSIVE_PROXY_CONFIG")
147
+ return ExclusiveProxyConf(**local_conf) if local_conf else None
148
+
149
+
150
+ class MysqlConfCreator(Creator):
151
+ def create_product(self, settings: Settings, consul_conf: dict) -> Product:
152
+ return MysqlConfProduct(settings, consul_conf)
153
+
154
+
155
+ class MongoDBConfCreator(Creator):
156
+ def create_product(self, settings: Settings, consul_conf: dict) -> Product:
157
+ return MongoDBConfProduct(settings, consul_conf)
158
+
159
+
160
+ class MQConfCreator(Creator):
161
+ def create_product(self, settings: Settings, consul_conf: dict) -> Product:
162
+ return MQConfProduct(settings, consul_conf)
163
+
164
+
165
+ class KafkaConfCreator(Creator):
166
+ def create_product(self, settings: Settings, consul_conf: dict) -> Product:
167
+ return KafkaConfProduct(settings, consul_conf)
168
+
169
+
170
+ class DynamicProxyCreator(Creator):
171
+ def create_product(self, settings: Settings, consul_conf: dict) -> Product:
172
+ return DynamicProxyProduct(settings, consul_conf)
173
+
174
+
175
+ class ExclusiveProxyCreator(Creator):
176
+ def create_product(self, settings: Settings, consul_conf: dict) -> Product:
177
+ return ExclusiveProxyProduct(settings, consul_conf)
178
+
179
+
180
+ def get_spider_conf(
181
+ product: Product,
182
+ ) -> Union[SpiderConf, None]:
183
+ return product.get_conn_conf()
@@ -7,7 +7,7 @@ __all__ = [
7
7
  SqlModeStr = Literal["and", "or"]
8
8
 
9
9
 
10
- class AboutSql(object):
10
+ class AboutSql:
11
11
  """
12
12
  sql 相关处理: sql 语句的管理方法,
13
13
  这里的 sql 拼接只能做到最简单的逻辑,如果需要灵活或稍复杂的情况,请参考 directsql, python-sql, pypika
@@ -15,6 +15,9 @@ __all__ = [
15
15
  "AiohttpConf",
16
16
  "AiohttpRequestArgs",
17
17
  "MQConf",
18
+ "KafkaConf",
19
+ "DynamicProxyConf",
20
+ "ExclusiveProxyConf",
18
21
  ]
19
22
 
20
23
  AiohttpRequestMethodStr = Literal["GET", "POST"]
@@ -51,7 +54,7 @@ class MysqlConf(NamedTuple):
51
54
  user: str
52
55
  password: str
53
56
  database: Optional[str] = None
54
- charset: Optional[str] = "utf8mb4"
57
+ charset: str = "utf8mb4"
55
58
 
56
59
 
57
60
  class MongoDBConf(NamedTuple):
@@ -99,13 +102,34 @@ class MQConf(NamedTuple):
99
102
  port: int
100
103
  username: str
101
104
  password: str
102
- virtualhost: Optional[str] = "/"
105
+ virtualhost: str = "/"
106
+ heartbeat: int = 0
107
+ socket_timeout: int = 1
103
108
  queue: Optional[str] = None
104
- durable: Optional[bool] = True
105
- exclusive: Optional[bool] = False
106
- auto_delete: Optional[bool] = False
109
+ durable: bool = True
110
+ exclusive: bool = False
111
+ auto_delete: bool = False
107
112
  exchange: Optional[str] = None
108
113
  routing_key: Optional[str] = None
109
- content_type: Optional[str] = "text/plain"
110
- delivery_mode: Optional[int] = 1
111
- mandatory: Optional[bool] = True
114
+ content_type: str = "text/plain"
115
+ delivery_mode: int = 1
116
+ mandatory: bool = True
117
+
118
+
119
+ class DynamicProxyConf(NamedTuple):
120
+ proxy: str
121
+ username: str
122
+ password: str
123
+
124
+
125
+ class ExclusiveProxyConf(NamedTuple):
126
+ proxy: str
127
+ username: str
128
+ password: str
129
+ index: int
130
+
131
+
132
+ class KafkaConf(NamedTuple):
133
+ bootstrap_servers: list
134
+ topic: str
135
+ key: str
@@ -22,10 +22,17 @@ __all__ = [
22
22
  ]
23
23
 
24
24
  ConsulFormatStr = Literal["json", "hcl", "yaml", "xml"]
25
- ConsulConfNameStr = Literal["mongodb", "mysql"]
25
+ ConsulConfNameStr = Literal[
26
+ "mongodb",
27
+ "mysql",
28
+ "rabbitmq",
29
+ "kafka",
30
+ "dynamicproxy",
31
+ "exclusiveproxy",
32
+ ]
26
33
 
27
34
 
28
- class ToolsForAyu(object):
35
+ class ToolsForAyu:
29
36
  """
30
37
  这里用于存放框架所依赖的方法
31
38
  """
@@ -9,7 +9,7 @@ __all__ = [
9
9
  ]
10
10
 
11
11
 
12
- class YiDunGetGap(object):
12
+ class YiDunGetGap:
13
13
  """
14
14
  易盾获取滑块缺口距离的相关方法,也可能适配于其它平台
15
15
  """
@@ -1,6 +1,5 @@
1
1
  from pathlib import Path
2
2
 
3
- from environs import Env
4
3
  from loguru import logger
5
4
 
6
5
  __all__ = [
@@ -9,11 +8,7 @@ __all__ = [
9
8
  ]
10
9
 
11
10
 
12
- env = Env()
13
- env.read_env()
14
-
15
-
16
- class NormalConfig(object):
11
+ class NormalConfig:
17
12
  """
18
13
  用于存放此项目的通用配置
19
14
  """
@@ -12,7 +12,7 @@ __all__ = [
12
12
  ]
13
13
 
14
14
 
15
- class DataHandle(object):
15
+ class DataHandle:
16
16
  """数据处理相关方法"""
17
17
 
18
18
  @staticmethod
@@ -11,7 +11,7 @@ __all__ = [
11
11
  ]
12
12
 
13
13
 
14
- class Picture(object):
14
+ class Picture:
15
15
  """
16
16
  对验证码图片的一些操作
17
17
  """
@@ -3,9 +3,6 @@ from ayugespidertools.scraper.middlewares.netlib.aiohttplib import (
3
3
  AiohttpAsyncDownloaderMiddleware,
4
4
  AiohttpDownloaderMiddleware,
5
5
  )
6
- from ayugespidertools.scraper.middlewares.netlib.requestslib import (
7
- RequestsDownloaderMiddleware,
8
- )
9
6
  from ayugespidertools.scraper.middlewares.proxy.dynamic import (
10
7
  AbuDynamicProxyDownloaderMiddleware,
11
8
  DynamicProxyDownloaderMiddleware,
@@ -18,7 +15,6 @@ __all__ = [
18
15
  "RandomRequestUaMiddleware",
19
16
  "AiohttpAsyncDownloaderMiddleware",
20
17
  "AiohttpDownloaderMiddleware",
21
- "RequestsDownloaderMiddleware",
22
18
  "AbuDynamicProxyDownloaderMiddleware",
23
19
  "DynamicProxyDownloaderMiddleware",
24
20
  "ExclusiveProxyDownloaderMiddleware",