Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
doudian-py
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
baiquan
doudian-py
Commits
fb51b8ad
Commit
fb51b8ad
authored
Apr 15, 2025
by
baiquan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add create_goods
parent
3be898da
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
491 additions
and
0 deletions
+491
-0
create_goods.py
+491
-0
No files found.
create_goods.py
0 → 100644
View file @
fb51b8ad
import
random
import
time
import
requests
from
doudian.login
import
login
headers
=
{
'Accept'
:
'application/json, text/plain, */*'
,
'Accept-Language'
:
'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6'
,
'Connection'
:
'keep-alive'
,
'Origin'
:
'https://fxg.jinritemai.com'
,
'Referer'
:
'https://fxg.jinritemai.com/'
,
'Sec-Fetch-Dest'
:
'empty'
,
'Sec-Fetch-Mode'
:
'cors'
,
'Sec-Fetch-Site'
:
'same-site'
,
'User-Agent'
:
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36 Edg/133.0.0.0'
,
'X-Requested-With'
:
'XMLHttpRequest'
,
'sec-ch-ua'
:
'"Not(A:Brand";v="99", "Microsoft Edge";v="133", "Chromium";v="133"'
,
}
def
get_freight_template_options
(
cookies
,
category_id
):
params
=
{
'action'
:
'freight_template_options_load'
,
'appid'
:
'1'
,
}
json_data
=
{
'context'
:
{
'category_id'
:
str
(
category_id
),
},
'appid'
:
1
,
}
response
=
requests
.
post
(
'https://fxg.jinritemai.com/product/tproduct/refetchSchema'
,
params
=
params
,
cookies
=
cookies
,
headers
=
headers
,
json
=
json_data
,
)
print
(
response
.
text
)
return
response
.
json
()[
'data'
][
'model'
]
def
get_spec_detail_options
(
cookies
,
category_id
):
params
=
{
'action'
:
'property_refresh_on_focus'
,
'appid'
:
'1'
,
}
json_data
=
{
'context'
:
{
'category_id'
:
str
(
category_id
),
},
'appid'
:
1
,
}
response
=
requests
.
post
(
'https://fxg.jinritemai.com/product/tproduct/refetchSchema'
,
params
=
params
,
cookies
=
cookies
,
headers
=
headers
,
json
=
json_data
,
)
print
(
response
.
json
()[
'data'
][
'model'
][
'category_properties'
][
'items'
])
return
response
.
json
()[
'data'
][
'model'
][
'category_properties'
][
'items'
]
def
search_category
(
cookies
,
key
):
params
=
{
'key'
:
key
,
'search_type'
:
'1'
,
'appid'
:
'1'
,
'_bid'
:
'ffa_goods'
,
}
response
=
requests
.
get
(
'https://fxg.jinritemai.com/product/tproduct/searchCategoryN'
,
params
=
params
,
cookies
=
cookies
,
headers
=
headers
,
)
print
(
response
.
text
)
return
response
.
json
()[
'data'
]
def
get_schema
(
cookies
,
category_id
):
json_data
=
{
'context'
:
{
'feature'
:
{},
'operation_type'
:
'select_normal,normal'
,
'category_id'
:
str
(
category_id
),
'ability'
:
[],
},
'appid'
:
1
,
'_bid'
:
'ffa_goods'
,
}
url
=
'https://fxg.jinritemai.com/product/tproduct/getSchema?appid=1'
response
=
requests
.
post
(
url
,
cookies
=
cookies
,
headers
=
headers
,
json
=
json_data
,
)
# print(response.text)
return
response
.
json
()[
'data'
]
def
upload_image
(
cookies
,
image_path_list
):
url
=
'https://fxg.jinritemai.com/product/img/batchupload?_bid=ffa_goods'
files
=
{}
for
i
,
image_path
in
enumerate
(
image_path_list
):
files
[
f
'image[{i}]'
]
=
(
'image.jpg'
,
open
(
image_path
,
'rb'
),
'image/jpeg'
)
response
=
requests
.
post
(
url
,
cookies
=
cookies
,
headers
=
headers
,
files
=
files
)
print
(
response
.
text
)
return
response
.
json
()[
'data'
]
def
upload_image_by_bytes
(
cookies
:
dict
,
image_bytes
:
list
[
bytes
]):
url
=
'https://fxg.jinritemai.com/product/img/batchupload?_bid=ffa_goods'
files
=
{}
for
i
,
bytes
in
enumerate
(
image_bytes
):
files
[
f
'image[{i}]'
]
=
(
'image.jpg'
,
bytes
,
'image/jpeg'
)
response
=
requests
.
post
(
url
,
cookies
=
cookies
,
headers
=
headers
,
files
=
files
)
print
(
response
.
text
)
return
response
.
json
()[
'data'
]
def
get_prettify_info
(
cookies
,
category_id
,
url_list
):
prettify_info
=
[]
for
url
in
url_list
:
prettify_info
.
append
({
'image'
:
{
'url'
:
url
,
},
})
json_data
=
{
'category_id'
:
int
(
category_id
),
'prettify_info'
:
prettify_info
}
response
=
requests
.
post
(
'https://fxg.jinritemai.com/product/prettify/formatPrettifyForProduct'
,
cookies
=
cookies
,
headers
=
headers
,
json
=
json_data
,
)
print
(
response
.
text
)
return
response
.
json
()[
'data'
]
def
generate_id
(
length
=
18
):
"""生成18位随机数字ID"""
return
str
(
random
.
randint
(
10
**
(
length
-
1
),
10
**
length
-
1
))
def
build_spec_structure
(
spec_params
):
# 数据结构初始化
result
=
{
'spec_detail'
:
{
'value'
:
[]},
'sku_detail'
:
{
'value'
:
[]}
}
# 生成默认规格(必须存在)
default_spec
=
{
'id'
:
'998077725005689370'
,
'is_default'
:
True
,
'name'
:
'默认'
,
'spec_values'
:
[{
'id'
:
'998146896366927369'
,
'name'
:
'默认'
}]
}
result
[
'spec_detail'
][
'value'
]
.
append
(
default_spec
)
# 处理有规格的情况
if
spec_params
[
'specs_name'
]:
spec_mapping
=
{}
# 生成规格模板(自动收集所有规格值)
for
index
,
spec_name
in
enumerate
(
spec_params
[
'specs_name'
]):
spec_id
=
generate_id
()
value_mapping
=
{}
# 收集所有规格值(去重)
all_values
=
list
(
set
(
spec
[
'values'
][
index
]
for
spec
in
spec_params
[
'specs_values'
]))
# 生成规格值ID
spec_values
=
[]
for
value
in
all_values
:
value_id
=
generate_id
()
if
spec_params
.
get
(
'specs_images'
):
if
spec_name
==
spec_params
[
'specs_images'
][
'specs_images_name'
]:
spec_values
.
append
(
{
'id'
:
value_id
,
'name'
:
value
,
'image_url'
:
spec_params
.
get
(
'specs_images'
)[
'specs_images_values'
][
value
]})
else
:
spec_values
.
append
({
'id'
:
value_id
,
'name'
:
value
})
value_mapping
[
value
]
=
value_id
spec_mapping
[
spec_name
]
=
value_mapping
result
[
'spec_detail'
][
'value'
]
.
append
({
'id'
:
spec_id
,
'name'
:
spec_name
,
'spec_values'
:
spec_values
,
'invalid'
:
False
})
# 生成SKU数据(直接使用配置中的组合)
for
sku
in
spec_params
[
'specs_values'
]:
sku_entry
=
{
'stock_info'
:
{
'stock_num'
:
sku
[
'stock_num'
]},
'sku_status'
:
True
,
'confirm_no_barcode'
:
False
,
'spec_detail_ids'
:
[],
'price'
:
str
(
sku
[
'price'
])
}
# 映射规格值ID
for
spec_name
,
value
in
zip
(
spec_params
[
'specs_name'
],
sku
[
'values'
]):
sku_entry
[
'spec_detail_ids'
]
.
append
(
spec_mapping
[
spec_name
][
value
])
if
not
sku_entry
[
'spec_detail_ids'
]:
sku_entry
[
'spec_detail_ids'
]
.
append
(
default_spec
[
'spec_values'
][
0
][
'id'
])
result
[
'sku_detail'
][
'value'
]
.
append
(
sku_entry
)
return
result
def
search_brand_prefix
(
cookies
,
category_id
,
brand_name
):
params
=
{
'cid'
:
str
(
category_id
),
'query'
:
brand_name
,
'appid'
:
'1'
,
}
url
=
'https://fxg.jinritemai.com/product/tproduct/brandPrefix'
response
=
requests
.
get
(
url
,
params
=
params
,
cookies
=
cookies
,
headers
=
headers
)
search_result
=
response
.
json
()[
'data'
]
print
(
search_result
)
if
not
search_result
:
return
None
return
search_result
[
0
]
def
add_with_schema
(
cookies
,
schema
,
goods_params
):
if
goods_params
.
get
(
'detail_prettify_image'
,
None
):
prettify_info
=
get_prettify_info
(
cookies
,
schema
[
'context'
][
'category_id'
],
goods_params
[
'detail_prettify_image'
])
else
:
prettify_info
=
get_prettify_info
(
cookies
,
schema
[
'context'
][
'category_id'
],
goods_params
[
'pic'
])
sku_data
=
build_spec_structure
(
goods_params
[
'spec_params'
])
pic
=
[]
for
url
in
goods_params
[
'pic'
]:
pic
.
append
({
'url'
:
url
,
})
main_image_three_to_four
=
[]
for
url
in
goods_params
[
'main_image_three_to_four'
]:
main_image_three_to_four
.
append
({
'url'
:
url
,
})
white_background_pic
=
[]
for
url
in
goods_params
[
'white_background_pic'
]:
white_background_pic
.
append
({
'url'
:
url
,
})
json_data
=
{
'schema'
:
{
'model'
:
{
'spec_detail'
:
sku_data
[
'spec_detail'
],
'sku_detail'
:
sku_data
[
'sku_detail'
],
'white_background_pic'
:
{
# 白底图
'value'
:
white_background_pic
,
},
'title'
:
{
# 商品标题
'value'
:
goods_params
[
'title'
],
},
'after_sale'
:
{
# 售后政策
'value'
:
{
'quality_problem_return'
:
{
'option_id'
:
None
,
'selected'
:
True
,
},
'supply_day_return_selector'
:
{
'option_id'
:
goods_params
.
get
(
'supply_day_return_selector'
,
'7-1'
),
# 7-1 7天无理由 7-3 7天无理由退货(安装后不支持) 7-5 7天无理由退货(使用后不支持) 7-6 7天无理由退货(定制类不支持)
'selected'
:
True
,
},
'three_guarantees'
:
{
# 售后服务承诺
'option_id'
:
goods_params
.
get
(
'three_guarantees'
,
'-1'
),
# -1 不包含 2 延长售后服务有效期
'selected'
:
True
,
},
},
},
'alli_promotion_plan_switch'
:
{
'value'
:
False
,
},
'area_stock_switcher'
:
{
'value'
:
False
,
},
'category_properties'
:
{
# 类目属性
'value'
:
{
'1345'
:
[
{
'value_id'
:
'35497'
,
'value_name'
:
'白色'
,
},
],
'1687'
:
[
{
'value_id'
:
'1879107146'
,
'value_name'
:
'NARWAL/云鲸'
,
'tags'
:
{
'brand_cn_name'
:
'云鲸'
,
},
},
],
'2398'
:
[
{
'value_id'
:
'7310'
,
'value_name'
:
'否'
,
},
],
'2426'
:
[
{
'value_id'
:
'23964'
,
'value_name'
:
'是'
,
},
],
'2592'
:
[
{
'value_id'
:
'37192'
,
'value_name'
:
'现代'
,
},
],
'3093'
:
[
{
'value_id'
:
'18444'
,
'value_name'
:
'木'
,
},
],
'3127'
:
[
{
'value_id'
:
'166314'
,
'value_name'
:
'木(非红木类)'
,
},
],
},
},
'delivery_delay_day'
:
{
# 现货发货时间 1 次日发 2 48小时 3 当日发 4 大于48小时发货
'value'
:
goods_params
.
get
(
'delivery_delay_day'
,
'1'
),
},
'description'
:
{
'value'
:
prettify_info
[
'description'
],
},
'freight_id'
:
{
# 运费模板
'value'
:
goods_params
[
'freight_id'
],
},
'goods_category'
:
{
# 商品类目
'value'
:
schema
[
'model'
][
'goods_category'
][
'value'
],
},
'interest_free_activity'
:
{
# 选择免息期数
'value'
:
[],
},
'interest_free_activity_id'
:
{
'value'
:
{
'activity_template_id'
:
schema
[
'model'
][
'interest_free_activity_id'
][
'value'
][
'activity_template_id'
],
},
},
'interest_free_open'
:
{
# 是否免息
'value'
:
False
,
},
'is_evaluate_opened'
:
{
'value'
:
True
,
},
'main_image_three_to_four'
:
{
# 主图3:4
'value'
:
main_image_three_to_four
,
},
'pic'
:
{
# 主图
'value'
:
pic
,
},
# 'main_pic_video': { # 主图视频
# 'value': [{
# "resource_id": "v03ecag10000cvscg4vog65n5earpkjg", # video_id
# "video_choice": 1
# }],
# },
'pickup_method'
:
{
'value'
:
'0'
,
},
'presell_type'
:
{
'value'
:
'0'
,
},
'product_type'
:
{
'value'
:
'0'
,
},
'qualification'
:
{
# 商品购买要求
'value'
:
{},
},
'reduce_type'
:
{
# 订单库存计数
'value'
:
goods_params
.
get
(
'reduce_type'
,
'1'
),
# 1 下单减库存 2 付款减库存
},
'short_product_name'
:
{
'value'
:
goods_params
.
get
(
'short_product_name'
,
''
),
# 导购短标题
},
'start_sale_type'
:
{
# 商品状态 0 上架 1 下架
'value'
:
goods_params
.
get
(
'start_sale_type'
,
'0'
),
},
'title_prefix'
:
{
'value'
:
''
,
},
'title_suffix'
:
{
# 标题后缀
'value'
:
''
,
},
'title_use_brand_name'
:
{
# 标题是否使用品牌名
'value'
:
goods_params
.
get
(
'title_use_brand_name'
,
False
),
},
'detail_prettify_uri'
:
{
'value'
:
prettify_info
[
'detail_prettify_uri'
],
},
},
'context'
:
schema
[
'context'
],
},
'pass_through_extra'
:
{},
'check_status'
:
2
,
'session'
:
{},
'appid'
:
1
,
}
if
goods_params
.
get
(
'three_guarantees'
)
==
'2'
and
goods_params
.
get
(
'extended_duration'
):
json_data
[
'schema'
][
'model'
][
'extended_duration'
]
=
{
# 选择售后有效期
'option_id'
:
goods_params
.
get
(
'extended_duration'
,
'30'
),
# 30 30天 60 60天 90 90天 120 120天 180 180天 365 1年
'selected'
:
True
,
}
print
(
json_data
)
url
=
'https://fxg.jinritemai.com/product/tproduct/addWithSchema?check_status=2&appid=1'
response
=
requests
.
post
(
url
,
cookies
=
cookies
,
headers
=
headers
,
json
=
json_data
)
print
(
response
.
text
)
if
__name__
==
'__main__'
:
account
=
'dybaihuo58@163.com'
password
=
'Cc123123'
# cookies = login(account, password, headers)
cookies
=
{
'PHPSESSID'
:
'06c1a5eb0db6263a5cb2d8cd7fcdcd1f'
,
'PHPSESSID_SS'
:
'06c1a5eb0db6263a5cb2d8cd7fcdcd1f'
,
}
pic_image_path_list
=
[
'image1.jpg'
,
'image2.jpg'
,
'image3.jpg'
,
'image4.jpg'
,
'image5.jpg'
]
image_bytes
=
[]
for
image_path
in
pic_image_path_list
:
with
open
(
image_path
,
'rb'
)
as
f
:
image_bytes
.
append
(
f
.
read
())
pic_image_url_list
=
upload_image_by_bytes
(
cookies
,
image_bytes
)
goods_params
=
{
'title'
:
'现代沙发岩板边几客厅小边桌轻奢角几云鲸科沃斯石头扫地机置物架'
,
# 'short_product_name': '现代沙发岩板边几客厅小边桌轻奢角几云鲸科沃斯石头扫地机置物架',
'title_use_brand_name'
:
False
,
'category_properties'
:
''
,
'pic'
:
pic_image_url_list
,
'main_image_three_to_four'
:
[],
'white_background_pic'
:
[],
'detail_prettify_image'
:
[],
'delivery_delay_day'
:
'2'
,
# 现货发货时间 1 次日发 2 48小时 3 当日发 4 大于48小时发货
'reduce_type'
:
'1'
,
# 1 下单减库存 2 付款减库存
'freight_id'
:
'640336706'
,
'supply_day_return_selector'
:
'7-1'
,
# 7-1 7天无理由 7-3 7天无理由退货(安装后不支持) 7-5 7天无理由退货(使用后不支持) 7-6 7天无理由退货(定制类不支持)
'three_guarantees'
:
'-1'
,
# -1 不包含 2 延长售后服务有效期
# 'extended_duration': '30', # 延长售后服务有效期 30 30天 60 60天 90 90天 120 120天 180 180天 365 1年
'start_sale_type'
:
'0'
,
# 商品状态 0 上架 1 下架
'spec_params'
:
{
# 'specs_name': [],
'specs_name'
:
[
'颜色'
,
'size'
],
# 'specs_images': {
# 'specs_images_name': '颜色',
# 'specs_images_values': {
# '黑': 'image1.jpg',
# '白': 'image2.jpg',
# '红': 'image3.jpg'
# }
# },
'specs_values'
:
[
{
'values'
:
[
'黑'
,
'S'
],
'price'
:
100
,
'stock_num'
:
0
},
{
'values'
:
[
'白'
,
'S'
],
'price'
:
100
,
'stock_num'
:
0
},
{
'values'
:
[
'红'
,
'S'
],
'price'
:
100
,
'stock_num'
:
0
},
{
'values'
:
[
'黑'
,
'M'
],
'price'
:
100
,
'stock_num'
:
0
},
{
'values'
:
[
'白'
,
'M'
],
'price'
:
100
,
'stock_num'
:
0
},
{
'values'
:
[
'红'
,
'M'
],
'price'
:
100
,
'stock_num'
:
0
},
{
'values'
:
[
'黑'
,
'L'
],
'price'
:
100
,
'stock_num'
:
0
},
{
'values'
:
[
'白'
,
'L'
],
'price'
:
100
,
'stock_num'
:
0
},
{
'values'
:
[
'红'
,
'L'
],
'price'
:
100
,
'stock_num'
:
0
},
{
'values'
:
[
'黑'
,
'XL'
],
'price'
:
100
,
'stock_num'
:
0
},
{
'values'
:
[
'白'
,
'XL'
],
'price'
:
100
,
'stock_num'
:
0
},
{
'values'
:
[
'红'
,
'XL'
],
'price'
:
100
,
'stock_num'
:
0
},
# {'values': [], 'price': 100, 'stock_num': 100},
]
}
}
# key = '现代沙发岩板边几客厅小边桌轻奢角几云鲸科沃斯石头扫地机置物架'
key
=
'悬挂式抽纸家用实惠装纸巾卫生间挂式厕纸大包学生擦手纸面巾纸'
# category_id = search_category(cookies, key)[0]['id']
category_id
=
search_category
(
cookies
,
key
)[
0
][
'id'
]
get_spec_detail_options
(
cookies
,
category_id
)
search_brand_prefix
(
cookies
,
category_id
,
'Redmi'
)
# schema = get_schema(cookies, category_id)
# add_with_schema(cookies, schema, goods_params)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment