Skip to content

Commit

Permalink
improve error message & unified style
Browse files Browse the repository at this point in the history
  • Loading branch information
shengchenyang committed Oct 15, 2023
1 parent de89984 commit 324d8f3
Show file tree
Hide file tree
Showing 8 changed files with 6 additions and 14 deletions.
5 changes: 1 addition & 4 deletions ayugespidertools/scraper/pipelines/mongo/asynced.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ def __init__(self):
self.db = None

def open_spider(self, spider):
assert hasattr(
spider, "mongodb_conf"
), "未配置 MongoDB 连接信息,请查看 .conf 或 consul 上对应配置信息!"

assert hasattr(spider, "mongodb_conf"), "未配置 MongoDB 连接信息!"
_encoded_pwd = urllib.parse.quote_plus(spider.mongodb_conf.password)
self.mongo_uri = (
f"mongodb://{spider.mongodb_conf.user}:{_encoded_pwd}"
Expand Down
4 changes: 1 addition & 3 deletions ayugespidertools/scraper/pipelines/mongo/fantasy.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ def __init__(self):
self.sys_ver_low = sys.version_info < (3, 11)

def open_spider(self, spider):
assert hasattr(
spider, "mongodb_conf"
), "未配置 MongoDB 连接信息,请查看 .conf 或 consul 上对应配置信息!"
assert hasattr(spider, "mongodb_conf"), "未配置 MongoDB 连接信息!"
super(AyuFtyMongoPipeline, self).__init__(
user=spider.mongodb_conf.user,
password=spider.mongodb_conf.password,
Expand Down
1 change: 1 addition & 0 deletions ayugespidertools/scraper/pipelines/msgproducer/kafkapub.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ def __init__(self):
self.kp = None

def open_spider(self, spider):
assert hasattr(spider, "kafka_conf"), "未配置 kafka 连接信息!"
# 如果有多个 kafka 服务地址,用逗号分隔,会在此处拆分为列表
_bts = spider.kafka_conf.bootstrap_servers
bts_lst = _bts.split(",")
Expand Down
5 changes: 1 addition & 4 deletions ayugespidertools/scraper/pipelines/msgproducer/mqpub.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ def _dict_to_bytes(self, item: dict) -> bytes:
return bytes(item_json_str, encoding="utf-8")

def open_spider(self, spider):
assert hasattr(
spider, "rabbitmq_conf"
), "未配置 RabbitMQ 连接信息,请查看 .conf 或 consul 上对应配置信息!"

assert hasattr(spider, "rabbitmq_conf"), "未配置 RabbitMQ 连接信息!"
_mq_conf = spider.rabbitmq_conf
mq_conn_param = pika.URLParameters(
f"amqp://{_mq_conf.username}:{_mq_conf.password}"
Expand Down
1 change: 0 additions & 1 deletion ayugespidertools/scraper/pipelines/mysql/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ def from_crawler(cls, crawler):

def open_spider(self, spider):
assert hasattr(spider, "mysql_conf"), "未配置 Mysql 连接信息!"

self.slog = spider.slog
self.mysql_conf = spider.mysql_conf
self.collate = ToolsForAyu.get_collate_by_charset(mysql_conf=self.mysql_conf)
Expand Down
2 changes: 0 additions & 2 deletions ayugespidertools/scraper/pipelines/mysql/asynced.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ class AsyncNormalMysqlPipeline(AyuMysqlPipeline):

def open_spider(self, spider):
assert hasattr(spider, "mysql_conf"), "未配置 Mysql 连接信息!"

self.slog = spider.slog
self.mysql_conf = spider.mysql_conf
self.collate = ToolsForAyu.get_collate_by_charset(mysql_conf=spider.mysql_conf)
Expand Down Expand Up @@ -64,7 +63,6 @@ class AsyncMysqlPipeline(AyuMysqlPipeline):

def open_spider(self, spider):
assert hasattr(spider, "mysql_conf"), "未配置 Mysql 连接信息!"

self.slog = spider.slog
self.mysql_conf = spider.mysql_conf
self.collate = ToolsForAyu.get_collate_by_charset(mysql_conf=spider.mysql_conf)
Expand Down
1 change: 1 addition & 0 deletions ayugespidertools/scraper/pipelines/mysql/turbo.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def from_crawler(cls, crawler):
)

def open_spider(self, spider):
assert hasattr(spider, "mysql_conf"), "未配置 Mysql 连接信息!"
self.slog = spider.slog
if not self.pool_db_conf:
spider.slog.warning("未配置 POOL_DB_CONFIG 参数,将使用其默认参数")
Expand Down
1 change: 1 addition & 0 deletions ayugespidertools/scraper/pipelines/mysql/twisted.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def __init__(self, *args, **kwargs):
self.dbpool = None

def open_spider(self, spider):
assert hasattr(spider, "mysql_conf"), "未配置 Mysql 连接信息!"
self.slog = spider.slog
self.mysql_conf = spider.mysql_conf
self.collate = ToolsForAyu.get_collate_by_charset(mysql_conf=self.mysql_conf)
Expand Down

0 comments on commit 324d8f3

Please sign in to comment.