拉取易仓API的亚马逊Listing数据-listing表现接口
设计一个程序,按照api返回的json数据自动生成一张表,并且表的ID为xxxxxxxxxx,
提供一个通用的接口:save_date_to_table_id,这个接口应该是自动判断存在的列的并集,然后按照id做insert操作或者是update操作。
拉去亚马逊Listing表现数据接口代码如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | import datetime import json import time import requests import op_data_web_hook as webhook app_key = "xxxxx" app_secret = "xxxxxx" def get_ecc_listing_so(page, seed): url = "http://home.eccang.com/openApi/api/unity" star_time = datetime.datetime.now() + datetime.timedelta(days = - 732 * seed) end_time = datetime.datetime.now() + datetime.timedelta(days = - 732 * (seed - 1 )) data_dict = { "page" : page, "page_size" : 100 , 'start_time' : star_time.strftime( '%Y-%m-%d %H:%M:%S' ), 'end_time' : end_time.strftime( '%Y-%m-%d %H:%M:%S' ) } payload = str (json.dumps(data_dict)) params = { "app_key" : app_key, "biz_content" : payload, "charset" : 'UTF-8' , "interface_method" : "ListingPerformance" , "nonce_str" : webhook.get_uuid(), "service_id" : "ETTIS6" , "sign_type" : "MD5" , "timestamp" : int (time.time() * 1000 ), "version" : "V1.0.0" } md5key_list = [] for key, val in params.items(): md5key_list.append( str (key) + '=' + str (val)) md5key_str = str ( '&' .join(md5key_list)) + str (app_secret) params[ "sign" ] = webhook.get_md5(md5key_str) ps = json.dumps(params) headers = { 'Content-Type' : 'application/json' } response = requests.request( "POST" , url, headers = headers, data = ps) res = response.text res = res.replace( "0000-00-00" , "2000-01-01" ) dict = json.loads(res) dict = dict [ "biz_content" ] dict = json.loads( dict ) data = dict [ "data" ] if len (data) = = 0 : return 0 for x in data: print (x) id = str (x[ "id" ]) x[ "shop_order_amount" ] = str (x[ "shop_order_amount" ]) x[ "listing_shop_sale_account_total" ] = str (x[ "listing_shop_sale_account_total" ]) x[ "sub_depart_name" ] = json.dumps(x[ "sub_depart_name" ], ensure_ascii = False ) x[ "tags" ] = json.dumps(x[ "tags" ], ensure_ascii = False ) x[ "fulfillment_type" ] = json.dumps(x[ "fulfillment_type" ], ensure_ascii = False ) x[ "compare_data" ] = json.dumps(x[ "compare_data" ], ensure_ascii = False ) x[ "keywords" ] = json.dumps(x[ "keywords" ], ensure_ascii = False ) x[ "principal_names" ] = json.dumps([ "principal_names" ], ensure_ascii = False ) if "bsr_category_ary" in x: bsr_category_ary = x[ "bsr_category_ary" ] for bsr in bsr_category_ary: bsr[ "id" ] = webhook.get_md5( id + str (bsr[ "bsr_num" ])) bsr[ "pid" ] = id webhook.post_data_to_db(bsr_category_ary, "ddac0125a0184039b65824572bc3bc34" ) del x[ "bsr_category_ary" ] if "product_sku_json" in x: product_sku_json = x[ "product_sku_json" ] for p in product_sku_json: p[ "id" ] = webhook.get_md5( id + str (p[ "id" ])) p[ "pid" ] = id webhook.post_data_to_db(product_sku_json, "a67db211e9154a62b659073697517e52" ) del x[ "product_sku_json" ] webhook.post_data_to_db(data, "438fd1d9258f4c12ad83998981811d80" ) return 1 # https://open.eccang.com/#/documentCenter?docId=1297&catId=0-225-225,0-177%23%2FdocumentCenter%3FdocId%3D1297&catId=0-225-225,0-177 if __name__ = = '__main__' : print ( "run at:" + webhook.time_to_str(datetime.datetime.now())) x = 1 while True : if x > 100 : break print (x) if get_ecc_listing_so(x, 1 ) = = 0 : break x = x + 1 print ( "run done at:" + webhook.time_to_str(datetime.datetime.now())) |
done
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· DeepSeek 开源周回顾「GitHub 热点速览」