@@ -18,42 +18,53 @@ JOS = settings.JOS['TAMRON'] |
||
| 18 | 18 |
def refresh_stock_info(): |
| 19 | 19 |
jd.setDefaultAppInfo(JOS['appkey'], JOS['secret']) |
| 20 | 20 |
|
| 21 |
- a = VcItemProductsFindRequest() |
|
| 22 |
- a.brand_id = 16795 |
|
| 23 |
- a.category_id = 834 |
|
| 24 |
- |
|
| 25 |
- try: |
|
| 26 |
- f = a.getResponse(JOS['accessToken']) |
|
| 27 |
- print(json.dumps(f)) |
|
| 28 |
- except Exception, e: |
|
| 29 |
- print(e) |
|
| 30 |
- |
|
| 31 |
- products = f['jingdong_vc_item_products_find_responce']['jos_result_dto']['result'] |
|
| 32 |
- print products |
|
| 33 |
- |
|
| 34 |
- ware_ids = [int(p['ware_id']) for p in products] |
|
| 35 |
- print ware_ids |
|
| 36 |
- |
|
| 37 |
- a = VcAplsStockBatchGetProdStockInfoRequest() |
|
| 38 |
- a.vendorCode = JOS['vendorCode'] |
|
| 39 |
- a.skuList = list(set(ware_ids) - set(settings.JOS_SKU_EXCLUDE)) |
|
| 40 |
- |
|
| 41 |
- try: |
|
| 42 |
- f = a.getResponse(JOS['accessToken']) |
|
| 43 |
- print(json.dumps(f)) |
|
| 44 |
- except Exception, e: |
|
| 45 |
- print(e) |
|
| 46 |
- |
|
| 47 |
- stocks = f['jingdong_vc_apls_stock_batchGetProdStockInfo_responce']['batchGetProdStockInfoResponse']['stockList'] |
|
| 48 |
- for stock in stocks: |
|
| 49 |
- print stock['sku'] |
|
| 50 |
- s, _ = StockInfo.objects.get_or_create(vendorProductId=stock['sku']) |
|
| 51 |
- s.vendorProductName = stock['wname'] |
|
| 52 |
- s.vendorCode = JOS['vendorCode'] |
|
| 53 |
- s.vendorName = JOS['vendorName'] |
|
| 54 |
- s.storeId = JOS['storeId'] |
|
| 55 |
- s.storeName = JOS['storeName'] |
|
| 56 |
- s.save() |
|
| 21 |
+ offset = 0 |
|
| 22 |
+ jcontinue = True |
|
| 23 |
+ while jcontinue: |
|
| 24 |
+ a = VcItemProductsFindRequest() |
|
| 25 |
+ a.brand_id = 16795 |
|
| 26 |
+ a.category_id = 834 |
|
| 27 |
+ a.offset = offset |
|
| 28 |
+ a.page_size = 50 |
|
| 29 |
+ |
|
| 30 |
+ try: |
|
| 31 |
+ f = a.getResponse(JOS['accessToken']) |
|
| 32 |
+ print(json.dumps(f)) |
|
| 33 |
+ except Exception, e: |
|
| 34 |
+ print(e) |
|
| 35 |
+ |
|
| 36 |
+ products = f['jingdong_vc_item_products_find_responce']['jos_result_dto']['result'] |
|
| 37 |
+ print products |
|
| 38 |
+ |
|
| 39 |
+ ware_ids = [int(p['ware_id']) for p in products] |
|
| 40 |
+ print ware_ids |
|
| 41 |
+ |
|
| 42 |
+ offset += 50 |
|
| 43 |
+ a.offset += offset |
|
| 44 |
+ |
|
| 45 |
+ if len(ware_ids) < 50: |
|
| 46 |
+ jcontinue = False |
|
| 47 |
+ |
|
| 48 |
+ a = VcAplsStockBatchGetProdStockInfoRequest() |
|
| 49 |
+ a.vendorCode = JOS['vendorCode'] |
|
| 50 |
+ a.skuList = list(set(ware_ids) - set(settings.JOS_SKU_EXCLUDE)) |
|
| 51 |
+ |
|
| 52 |
+ try: |
|
| 53 |
+ f = a.getResponse(JOS['accessToken']) |
|
| 54 |
+ print(json.dumps(f)) |
|
| 55 |
+ except Exception, e: |
|
| 56 |
+ print(e) |
|
| 57 |
+ |
|
| 58 |
+ stocks = f['jingdong_vc_apls_stock_batchGetProdStockInfo_responce']['batchGetProdStockInfoResponse']['stockList'] |
|
| 59 |
+ for stock in stocks: |
|
| 60 |
+ print stock['sku'] |
|
| 61 |
+ s, _ = StockInfo.objects.get_or_create(vendorProductId=stock['sku']) |
|
| 62 |
+ s.vendorProductName = stock['wname'] |
|
| 63 |
+ s.vendorCode = JOS['vendorCode'] |
|
| 64 |
+ s.vendorName = JOS['vendorName'] |
|
| 65 |
+ s.storeId = JOS['storeId'] |
|
| 66 |
+ s.storeName = JOS['storeName'] |
|
| 67 |
+ s.save() |
|
| 57 | 68 |
|
| 58 | 69 |
|
| 59 | 70 |
def update_stock_info(stock): |