fix(card): 新增渠道cic
This commit is contained in:
42
alembic/versions/6bd2808b89b3_fix_product.py
Normal file
42
alembic/versions/6bd2808b89b3_fix_product.py
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
"""fix product
|
||||||
|
|
||||||
|
Revision ID: 6bd2808b89b3
|
||||||
|
Revises: 2d63d72e671a
|
||||||
|
Create Date: 2025-05-06 17:26:55.406210
|
||||||
|
|
||||||
|
"""
|
||||||
|
from typing import Sequence, Union
|
||||||
|
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
from sqlalchemy.dialects import mysql
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision: str = '6bd2808b89b3'
|
||||||
|
down_revision: Union[str, None] = '2d63d72e671a'
|
||||||
|
branch_labels: Union[str, Sequence[str], None] = None
|
||||||
|
depends_on: Union[str, Sequence[str], None] = None
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade() -> None:
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
op.alter_column('system_chats', 'is_deleted',
|
||||||
|
existing_type=mysql.TINYINT(display_width=4),
|
||||||
|
nullable=False)
|
||||||
|
op.alter_column('system_users', 'avatar_url',
|
||||||
|
existing_type=mysql.VARCHAR(length=500),
|
||||||
|
nullable=True,
|
||||||
|
existing_comment='头像链接')
|
||||||
|
# ### end Alembic commands ###
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade() -> None:
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
op.alter_column('system_users', 'avatar_url',
|
||||||
|
existing_type=mysql.VARCHAR(length=500),
|
||||||
|
nullable=False,
|
||||||
|
existing_comment='头像链接')
|
||||||
|
op.alter_column('system_chats', 'is_deleted',
|
||||||
|
existing_type=mysql.TINYINT(display_width=4),
|
||||||
|
nullable=True)
|
||||||
|
# ### end Alembic commands ###
|
||||||
48
alembic/versions/e2a204afe670_new_add_support_platform.py
Normal file
48
alembic/versions/e2a204afe670_new_add_support_platform.py
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
"""new add support platform
|
||||||
|
|
||||||
|
Revision ID: e2a204afe670
|
||||||
|
Revises: 6bd2808b89b3
|
||||||
|
Create Date: 2025-05-06 21:36:32.322778
|
||||||
|
|
||||||
|
"""
|
||||||
|
from typing import Sequence, Union
|
||||||
|
|
||||||
|
from alembic import op
|
||||||
|
import sqlalchemy as sa
|
||||||
|
from sqlalchemy.dialects import mysql
|
||||||
|
|
||||||
|
# revision identifiers, used by Alembic.
|
||||||
|
revision: str = 'e2a204afe670'
|
||||||
|
down_revision: Union[str, None] = '6bd2808b89b3'
|
||||||
|
branch_labels: Union[str, Sequence[str], None] = None
|
||||||
|
depends_on: Union[str, Sequence[str], None] = None
|
||||||
|
|
||||||
|
|
||||||
|
def upgrade() -> None:
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
op.alter_column('system_cache_cards', 'source',
|
||||||
|
existing_type=mysql.ENUM('PSA', 'BGS', 'CGC', 'GBTC', 'CCG', 'BCTC', 'CIC'),
|
||||||
|
comment='数据来源:PSA、BGS、CGC、GBTC、CCG、BCTC、CIC',
|
||||||
|
existing_comment='数据来源:PSA、BGS、CGC、GBTC、CCG、BCTC',
|
||||||
|
existing_nullable=False)
|
||||||
|
op.alter_column('system_cards', 'source',
|
||||||
|
existing_type=mysql.ENUM('PSA', 'BGS', 'CGC', 'GBTC', 'CCG', 'BCTC', 'CIC', 'OTHER'),
|
||||||
|
comment='来源,PSA、BGS、CGC、GBTC、CCG、BCTC、CIC :采集 、OTHER:自定义',
|
||||||
|
existing_comment='来源,PSA、BGS、CGC、GBTC、CCG、BCTC :采集 、OTHER:自定义',
|
||||||
|
existing_nullable=False)
|
||||||
|
# ### end Alembic commands ###
|
||||||
|
|
||||||
|
|
||||||
|
def downgrade() -> None:
|
||||||
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
|
op.alter_column('system_cards', 'source',
|
||||||
|
existing_type=mysql.ENUM('PSA', 'BGS', 'CGC', 'GBTC', 'CCG', 'BCTC', 'OTHER'),
|
||||||
|
comment='来源,PSA、BGS、CGC、GBTC、CCG、BCTC :采集 、OTHER:自定义',
|
||||||
|
existing_comment='来源,PSA、BGS、CGC、GBTC、CCG、BCTC、CIC :采集 、OTHER:自定义',
|
||||||
|
existing_nullable=False)
|
||||||
|
op.alter_column('system_cache_cards', 'source',
|
||||||
|
existing_type=mysql.ENUM('PSA', 'BGS', 'CGC', 'GBTC', 'CCG', 'BCTC'),
|
||||||
|
comment='数据来源:PSA、BGS、CGC、GBTC、CCG、BCTC',
|
||||||
|
existing_comment='数据来源:PSA、BGS、CGC、GBTC、CCG、BCTC、CIC',
|
||||||
|
existing_nullable=False)
|
||||||
|
# ### end Alembic commands ###
|
||||||
@@ -32,6 +32,7 @@ class SupportPlatformType(enum.Enum):
|
|||||||
GBTC = 'gbtc'
|
GBTC = 'gbtc'
|
||||||
CCG = 'ccg'
|
CCG = 'ccg'
|
||||||
BCTC = 'bctc'
|
BCTC = 'bctc'
|
||||||
|
CIC = 'cic'
|
||||||
|
|
||||||
|
|
||||||
class PlatformSourceType(enum.Enum):
|
class PlatformSourceType(enum.Enum):
|
||||||
@@ -41,6 +42,7 @@ class PlatformSourceType(enum.Enum):
|
|||||||
GBTC = 'gbtc'
|
GBTC = 'gbtc'
|
||||||
CCG = 'ccg'
|
CCG = 'ccg'
|
||||||
BCTC = 'bctc'
|
BCTC = 'bctc'
|
||||||
|
CIC = 'cic'
|
||||||
OTHER = 'other'
|
OTHER = 'other'
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -154,7 +154,7 @@ class Card(BaseModel, DateModel):
|
|||||||
)
|
)
|
||||||
source: Mapped[str] = mapped_column(
|
source: Mapped[str] = mapped_column(
|
||||||
Enum(base_schema.PlatformSourceType, inherit_schema=True),
|
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='自定义品牌名')
|
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='原始数据')
|
raw_data: Mapped[dict] = mapped_column(JSON, comment='原始数据')
|
||||||
source: Mapped[str] = mapped_column(
|
source: Mapped[str] = mapped_column(
|
||||||
Enum(base_schema.SupportPlatformType, inherit_schema=True),
|
Enum(base_schema.SupportPlatformType, inherit_schema=True),
|
||||||
comment='数据来源:PSA、BGS、CGC、GBTC、CCG、BCTC'
|
comment='数据来源:PSA、BGS、CGC、GBTC、CCG、BCTC、CIC'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -165,6 +165,19 @@ class SiteApi:
|
|||||||
r = await self.post(url, headers=headers, json=payload)
|
r = await self.post(url, headers=headers, json=payload)
|
||||||
return r
|
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):
|
async def close(self):
|
||||||
await self.session.close()
|
await self.session.close()
|
||||||
|
|
||||||
@@ -184,6 +197,7 @@ class CardScraper:
|
|||||||
'gbtc': self.gbtc,
|
'gbtc': self.gbtc,
|
||||||
'ccg': self.ccg,
|
'ccg': self.ccg,
|
||||||
'bctc': self.bctc,
|
'bctc': self.bctc,
|
||||||
|
'cic': self.cic,
|
||||||
}
|
}
|
||||||
return self._handlers
|
return self._handlers
|
||||||
|
|
||||||
@@ -197,7 +211,8 @@ class CardScraper:
|
|||||||
info_elements = html.xpath('//div[@hidden and @id]/div[contains(@class, "py-3")]')
|
info_elements = html.xpath('//div[@hidden and @id]/div[contains(@class, "py-3")]')
|
||||||
info = dict()
|
info = dict()
|
||||||
for info_element in info_elements:
|
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 = re.sub(r'\(|\)', '', name)
|
||||||
name = name.lower().replace(' ', '_').replace('/', '_')
|
name = name.lower().replace(' ', '_').replace('/', '_')
|
||||||
value = info_element.xpath('./dd[1]').xpath('string()').get()
|
value = info_element.xpath('./dd[1]').xpath('string()').get()
|
||||||
@@ -430,7 +445,43 @@ class CardScraper:
|
|||||||
return {
|
return {
|
||||||
'cert_number': item['cert_number'],
|
'cert_number': item['cert_number'],
|
||||||
'data': item,
|
'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:
|
async def choice(self, platform: str, cert_number: str | int) -> dict | None:
|
||||||
|
|||||||
Reference in New Issue
Block a user