fix(card): 新增渠道cic

This commit is contained in:
xingc
2025-05-06 21:51:02 +08:00
parent 2b6b53b13d
commit 30a03efd3b
5 changed files with 147 additions and 4 deletions

View File

@@ -32,6 +32,7 @@ class SupportPlatformType(enum.Enum):
GBTC = 'gbtc'
CCG = 'ccg'
BCTC = 'bctc'
CIC = 'cic'
class PlatformSourceType(enum.Enum):
@@ -41,6 +42,7 @@ class PlatformSourceType(enum.Enum):
GBTC = 'gbtc'
CCG = 'ccg'
BCTC = 'bctc'
CIC = 'cic'
OTHER = 'other'

View File

@@ -154,7 +154,7 @@ class Card(BaseModel, DateModel):
)
source: Mapped[str] = mapped_column(
Enum(base_schema.PlatformSourceType, inherit_schema=True),
comment='来源PSA、BGS、CGC、GBTC、CCG、BCTC :采集 、OTHER自定义'
comment='来源PSA、BGS、CGC、GBTC、CCG、BCTC、CIC :采集 、OTHER自定义'
)
diy_source: Mapped[str] = mapped_column(String(50), nullable=True, comment='自定义品牌名')
@@ -207,7 +207,7 @@ class SearchCardCache(BaseModel, DateModel):
raw_data: Mapped[dict] = mapped_column(JSON, comment='原始数据')
source: Mapped[str] = mapped_column(
Enum(base_schema.SupportPlatformType, inherit_schema=True),
comment='数据来源PSA、BGS、CGC、GBTC、CCG、BCTC'
comment='数据来源PSA、BGS、CGC、GBTC、CCG、BCTC、CIC'
)

View File

@@ -165,6 +165,19 @@ class SiteApi:
r = await self.post(url, headers=headers, json=payload)
return r
async def cic(self, cert_number: str | int):
"""中检检通"""
url = 'https://www.zhongjianjiantong.com/Api/OrderRatingGoods/detail'
payload = {
'cert_no': cert_number
}
headers = {
'Content-Type': 'application/json;charset=UTF-8',
'Referer': "https://www.zhongjianjiantong.com/web/index.html",
}
r = await self.post(url, headers=headers, json=payload)
return r
async def close(self):
await self.session.close()
@@ -184,6 +197,7 @@ class CardScraper:
'gbtc': self.gbtc,
'ccg': self.ccg,
'bctc': self.bctc,
'cic': self.cic,
}
return self._handlers
@@ -197,7 +211,8 @@ class CardScraper:
info_elements = html.xpath('//div[@hidden and @id]/div[contains(@class, "py-3")]')
info = dict()
for info_element in info_elements:
name = info_element.xpath('./dt[1]').xpath('string()').get() or info_element.xpath('./dt/template/@id').get() or ''
name = info_element.xpath('./dt[1]').xpath('string()').get() or info_element.xpath(
'./dt/template/@id').get() or ''
name = re.sub(r'\(|\)', '', name)
name = name.lower().replace(' ', '_').replace('/', '_')
value = info_element.xpath('./dd[1]').xpath('string()').get()
@@ -430,7 +445,43 @@ class CardScraper:
return {
'cert_number': item['cert_number'],
'data': item,
'raw_data': result.get('info'),
'raw_data': details,
}
async def cic(self, cert_number: str | int) -> dict | None:
"""中检检通"""
r = await self.api.cic(cert_number)
result = r.json()
if result.get('code') != 200:
return
details = jsonpath(result, '$.data.obj_order_rating_goods', first=True)
item = dict(cert_number=None)
# 评级卡号
item['cert_number'] = details.get('cert_no')
# 年份
item['card_year'] = jsonpath(details, '$.obj_detail.fxnf', first=True)
# 卡片品牌
item['card_brand'] = jsonpath(details, '$.obj_brand.title', first=True)
# 卡片评分
item['card_score'] = details.get('score')
# 卡片名称
item['card_name'] = details.get('goods_name')
# 卡片编号
item['card_number'] = details.get('tag_no')
# 卡片类型 无
# 卡片正、反图片(远程)
item['card_spare_picture'] = {
'front_picture': jsonpath(details, '$.lst_images[0]', first=True),
'reverse_picture': jsonpath(details, '$.lst_images[1]', first=True)
}
# 来源
item['source'] = 'cic'
return {
'cert_number': item['cert_number'],
'data': item,
'raw_data': details,
}
async def choice(self, platform: str, cert_number: str | int) -> dict | None: