列表套字典三者匹配对应关系
skuid对应普通发货价
# coding: utf-8
import requests
import time
import json
value_list=[{
"propertyId": 4665,
"name": "尺码",
"value": "35.5",
"propertyValueId": 20194173,
"level": 1,
"customValue": "",
"showValue": 1,
"sort": 0,
"definitionId": 6
}, {
"propertyId": 4665,
"name": "尺码",
"value": "36",
"propertyValueId": 20194174,
"level": 1,
"customValue": "",
"showValue": 1,
"sort": 1,
"definitionId": 6
}, {
"propertyId": 4665,
"name": "尺码",
"value": "36.5",
"propertyValueId": 20194175,
"level": 1,
"customValue": "",
"showValue": 1,
"sort": 2,
"definitionId": 6
}, {
"propertyId": 4665,
"name": "尺码",
"value": "37.5",
"propertyValueId": 20194176,
"level": 1,
"customValue": "",
"showValue": 1,
"sort": 3,
"definitionId": 6
}, {
"propertyId": 4665,
"name": "尺码",
"value": "38",
"propertyValueId": 20194177,
"level": 1,
"customValue": "",
"showValue": 1,
"sort": 4,
"definitionId": 6
}, {
"propertyId": 4665,
"name": "尺码",
"value": "48.5",
"propertyValueId": 20194191,
"level": 1,
"customValue": "",
"showValue": 1,
"sort": 22,
"definitionId": 6
}]
skus_list=[{
"skuId": 600070406,
"spuId": 1011006,
"authPrice": 0,
"status": 1,
"properties": [{
"level": 1,
"propertyValueId": 20194173
}]
}, {
"skuId": 600070407,
"spuId": 1011006,
"authPrice": 0,
"status": 1,
"properties": [{
"level": 1,
"propertyValueId": 20194174
}]
}, {
"skuId": 600070408,
"spuId": 1011006,
"authPrice": 0,
"status": 1,
"properties": [{
"level": 1,
"propertyValueId": 20194175
}]
}, {
"skuId": 600070409,
"spuId": 1011006,
"authPrice": 0,
"status": 1,
"properties": [{
"level": 1,
"propertyValueId": 20194176
}]
}, {
"skuId": 600070410,
"spuId": 1011006,
"authPrice": 0,
"status": 1,
"properties": [{
"level": 1,
"propertyValueId": 20194177
}]
}, {
"skuId": 600070424,
"spuId": 1011006,
"authPrice": 0,
"status": 1,
"properties": [{
"level": 1,
"propertyValueId": 20194191
}]
}]
info_List={
"code": 200,
"msg": "success",
"data": {
"skuInfoList": [{
"skuId": 600070406,
"faqType": -1
}, {
"skuId": 600070407,
"minPrice": 416900,
"tradeType": 2,
"tradeChannelInfoList": [{
"tradeType": 2,
"bidType": 5,
"tradeTypeName": "闪电直发",
"tradeDesc": "闪电直发",
"arrivalTimeText": "约2天到",
"tradeTypeText": "约2天到货",
"price": 416900,
"saleInventoryNo": "SN1068613848"
}, {
"tradeType": 0,
"bidType": 0,
"tradeTypeName": "立即购买",
"tradeDesc": "普通发货",
"arrivalTimeText": "约5天到",
"price": 444900,
"saleInventoryNo": "SN1068559548"
}],
"faqType": 2
}, {
"skuId": 600070408,
"minPrice": 416900,
"tradeType": 2,
"tradeChannelInfoList": [{
"tradeType": 2,
"bidType": 5,
"tradeTypeName": "闪电直发",
"tradeDesc": "闪电直发",
"arrivalTimeText": "约2天到",
"tradeTypeText": "约2天到货",
"price": 416900,
"saleInventoryNo": "SN1068098024"
}, {
"tradeType": 0,
"bidType": 0,
"tradeTypeName": "立即购买",
"tradeDesc": "普通发货",
"arrivalTimeText": "约5天到",
"price": 432900,
"saleInventoryNo": "SN1067938299"
}],
"faqType": 2
}, {
"skuId": 600070409,
"minPrice": 385900,
"tradeType": 0,
"tradeChannelInfoList": [{
"tradeType": 2,
"bidType": 5,
"tradeTypeName": "闪电直发",
"tradeDesc": "闪电直发",
"arrivalTimeText": "约2天到",
"tradeTypeText": "约2天到货",
"price": 408900,
"saleInventoryNo": "SN1068092623"
}, {
"tradeType": 0,
"bidType": 0,
"tradeTypeName": "立即购买",
"tradeDesc": "普通发货",
"arrivalTimeText": "约5天到",
"price": 385900,
"saleInventoryNo": "SN1068627769"
}],
"faqType": 2
}, {
"skuId": 600070410,
"minPrice": 350900,
"tradeType": 2,
"tradeChannelInfoList": [{
"tradeType": 2,
"bidType": 5,
"tradeTypeName": "闪电直发",
"tradeDesc": "闪电直发",
"arrivalTimeText": "约2天到",
"tradeTypeText": "约2天到货",
"price": 350900,
"saleInventoryNo": "SN1068377364"
}, {
"tradeType": 0,
"bidType": 0,
"tradeTypeName": "立即购买",
"tradeDesc": "普通发货",
"arrivalTimeText": "约5天到",
"price": 356900,
"saleInventoryNo": "SN1068148854"
}, {
"tradeType": 95,
"tradeTypeName": "全新微瑕",
"price": 300600,
"linkUrl": "https://m.poizon.com/mini/open?miniId=mini_95fen&options=%7B%22pt%22%3A%222%22%2C%22params%22%3A%7B%22goods_id%22%3A%22El0WZEdOR%22%2C%22title%22%3A%22Nike%20Dunk%20SB%20Laser%20Orange%20%5Cu767d%5Cu9ec4%5C%2F%5Cu7d2b%5Cu52feLow%22%7D%2C%22source%22%3A%22duAppSupplier%22%7D"
}],
"faqType": 2
}, {
"skuId": 600070411,
"minPrice": 333900,
"tradeType": 0,
"tradeChannelInfoList": [{
"tradeType": 2,
"bidType": 5,
"tradeTypeName": "闪电直发",
"tradeDesc": "闪电直发",
"arrivalTimeText": "约2天到",
"tradeTypeText": "约2天到货",
"price": 372900,
"saleInventoryNo": "SN1068642488"
}, {
"tradeType": 0,
"bidType": 0,
"tradeTypeName": "立即购买",
"tradeDesc": "普通发货",
"arrivalTimeText": "约5天到",
"price": 333900,
"saleInventoryNo": "SN1068276628"
}],
"faqType": 2
}, {
"skuId": 600070424,
"minPrice": 398900,
"tradeType": 0,
"tradeChannelInfoList": [{
"tradeType": 0,
"bidType": 0,
"tradeTypeName": "立即购买",
"tradeDesc": "普通发货",
"arrivalTimeText": "约5天到",
"price": 498900,
"saleInventoryNo": "SN1068107239"
}],
"faqType": -1
}],
"faqInfoList": [{
"faqType": 2,
"exchangeDesc": "闪电直发",
"exchangeUrl": "https://m.poizon.com/hybird/h5other/plus-sellerFlow"
}, {
"faqType": 1,
"exchangeDesc": "极速发货",
"exchangeUrl": "https://m.poizon.com/website/trade?extend=fast_logistics"
}],
"shipMode": {
"exchangeDesc": "交易模式",
"exchangeUrl": "https://m.poizon.com/nezha/detail/5ef053d32795fafc8d4a78f0"
},
"totalMinPrice": 308900,
"serverTime": 1601281396060,
"canShowArrivalBtn": True,
"timeThreshold": 100
},
"status": 200
}
"""{
'skuId':600070413,
'value':'40',
'generalPrice':315900
}"""
JSON字符串两两对应
def parsing_skuinfoList(value_list, skus_list, info_List):
value_map_propertyValueId = dict()
for _value in value_list:
if _value["propertyValueId"]:
value_map_propertyValueId[str(_value["propertyValueId"])] = _value["value"]
print("value_1111",value_map_propertyValueId)
sku_map_values = dict()
for _skus in skus_list:
# print(_skus)
skuId = _skus["skuId"]
status = _skus["status"]
properties = _skus["properties"]
if properties:
propertyValueId = properties[0]["propertyValueId"]
if str(propertyValueId) in value_map_propertyValueId:
sku_map_values[str(skuId)] = value_map_propertyValueId[str(propertyValueId)]
real_skus_list = list()
if info_List and isinstance(info_List, dict):
skuInfoList = info_List.get("data", dict()).get("skuInfoList")
if skuInfoList:
for __skuInfo in skuInfoList:
skuId = __skuInfo.get("skuId")
tradeChannelInfoList = __skuInfo.get("tradeChannelInfoList")
print(tradeChannelInfoList)
if not tradeChannelInfoList or not skuId:
continue
price = None
for trade_cl in tradeChannelInfoList:
if trade_cl.get("tradeTypeName", "") == "立即购买":
price = trade_cl.get("price") # SN1068550758
saleInventoryNo = trade_cl.get("saleInventoryNo") # SN1068550758
break
if price and skuId and str(skuId) in sku_map_values.keys():
real_skus_list.append({
'skuId': skuId,
'value': sku_map_values[str(skuId)],
'generalPrice': price
})
print(real_skus_list)
return real_skus_list
print(" error ")
if __name__ == '__main__':
parsing_skuinfoList(value_list, skus_list, info_List)
运行结果:
[{'skuId': 600070407, 'value': '36', 'generalPrice': 444900}, {'skuId': 600070408, 'value': '36.5', 'generalPrice': 432900}, {'skuId': 600070409, 'value': '37.5', 'generalPrice': 385900}, {'skuId': 600070410, 'value': '38', 'generalPrice': 356900}, {'skuId': 600070424, 'value': '48.5', 'generalPrice': 498900}]