MCPcopy
hub / github.com/tychxn/jd-assistant / parse_sku_id

Function parse_sku_id

util.py:143–170  ·  view source on GitHub ↗

将商品id字符串解析为字典 商品id字符串采用英文逗号进行分割。 可以在每个id后面用冒号加上数字,代表该商品的数量,如果不加数量则默认为1。 例如: 输入 --> 解析结果 '123456' --> {'123456': '1'} '123456,123789' --> {'123456': '1', '123789': '1'} '123456:1,123789:3' --> {'123456': '1', '123789': '3'} '123456:2,123789' --> {'123456': '2', '12

(sku_ids)

Source from the content-addressed store, hash-verified

141
142
143def parse_sku_id(sku_ids):
144 """将商品id字符串解析为字典
145
146 商品id字符串采用英文逗号进行分割。
147 可以在每个id后面用冒号加上数字,代表该商品的数量,如果不加数量则默认为1。
148
149 例如:
150 输入 --> 解析结果
151 '123456' --> {'123456': '1'}
152 '123456,123789' --> {'123456': '1', '123789': '1'}
153 '123456:1,123789:3' --> {'123456': '1', '123789': '3'}
154 '123456:2,123789' --> {'123456': '2', '123789': '1'}
155
156 :param sku_ids: 商品id字符串
157 :return: dict
158 """
159 if isinstance(sku_ids, dict): # 防止重复解析
160 return sku_ids
161
162 sku_id_list = list(filter(bool, map(lambda x: x.strip(), sku_ids.split(','))))
163 result = dict()
164 for item in sku_id_list:
165 if ':' in item:
166 sku_id, count = map(lambda x: x.strip(), item.split(':'))
167 result[sku_id] = count
168 else:
169 result[item] = '1'
170 return result
171
172
173def parse_area_id(area):

Callers 6

get_multi_item_stockMethod · 0.90
add_item_to_cartMethod · 0.90
exec_seckill_by_timeMethod · 0.90
buy_item_in_stockMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected