コード例 #1
0
def Createtoken(code):
    # params 1 : gateway url
    # params 2 : appkey
    # params 3 : appSecret
    # print(appKey)
    # print(appSecret)
    # print(code)
    client = lazop.LazopClient(Lazada_setup['authService'],
                               Lazada_setup['appKey'],
                               Lazada_setup['appSecret'])
    # create a api request set GET mehotd
    # default http method is POST
    request = lazop.LazopRequest('/auth/token/create')
    # simple type params ,Number ,String
    request.add_api_param('code', code)
    # request.add_api_param('uuid', '38284839234')
    response = client.execute(request)
    # ISP : API Service Provider Error
    # ISV : API Request Client Error
    # SYSTEM : Lazop platform Error
    print(response.type)
    # response code, 0 is no error
    print(response.code)

    # response error message
    print(response.message)

    # response unique id
    print(response.request_id)

    # full response
    print(response.body)
    json_payload = response
    print(json_payload.body)
    return json_payload
コード例 #2
0
 def remove_product(self, site, seller_sku_list):  #暴力
     url = self.new_dic[site.strip()].split(',')[2]
     access_token = self.new_dic[site.strip()].split(',')[0]
     client = lazop.LazopClient(url, self.appkey, self.appSecret)
     request = lazop.LazopRequest('/product/remove')
     request.add_api_param('seller_sku_list', seller_sku_list)
     response = client.execute(request, access_token)
     print(response.body)
コード例 #3
0
 def get_access_token(self, code):
     client = lazop.LazopClient(self.url, self.appkey, self.appSecret)
     request = lazop.LazopRequest('/auth/token/create')
     request.add_api_param('code', '%s' % code)
     response = client.execute(request)
     token_info = {}
     print response.body
     if response.code == '0':
         token_info['access_token'] = response.body['access_token']
         token_info['refresh_token'] = response.body['refresh_token']
     return token_info
コード例 #4
0
 def get_refresh_token(self, refresh_token):
     client = lazop.LazopClient(self.url, self.appkey, self.appSecret)
     request = lazop.LazopRequest('/auth/token/refresh')
     request.add_api_param('refresh_token', refresh_token)
     response = client.execute(request)
     print response.body
     token_info = {}
     if response.code == '0':
         token_info['access_token'] = response.body['access_token']
         token_info['refresh_token'] = response.body['refresh_token']
     print 'token信息已刷新'
     return token_info
コード例 #5
0
 def _py_client_lazada_request(self, *args, **kwargs):
     self.ensure_one()
     if '/auth/token/create' in args or '/auth/token/refresh' in args:
         url = 'https://auth.lazada.com/rest'
         token = None
     else:
         url = self.url
         token = self.access_token
     client = lazop.LazopClient(url, self.platform_id.partner_id,
                                self.platform_id.key)
     request = lazop.LazopRequest(*args)
     for k, v in kwargs.items():
         request.add_api_param(k, v)
     response = client.execute(request, token)
     #_logger.info(response.__dict__)
     return response.body
コード例 #6
0
 def up_down_shelves(self, site, SellerSku, flag):
     new_messages = {}
     url = self.new_dic[site.strip()].split(',')[2]
     access_token = self.new_dic[site.strip()].split(',')[0]
     client = lazop.LazopClient(url, self.appkey, self.appSecret)
     request = lazop.LazopRequest('/product/update')
     if isinstance(SellerSku, list):
         for sk in SellerSku:
             for k, v in sk.items():
                 xml_one = '<?xml version="1.0" encoding="UTF-8"?><Request><Product><Skus>'
                 for vv in v:
                     xml_one = '%s<Sku><SellerSku>%s</SellerSku><active>%s</active></Sku>' % (
                         xml_one, vv, flag)
                 xml_one = '%s</Skus></Product></Request>' % xml_one
                 request.add_api_param('payload', xml_one)
                 response = client.execute(request, access_token)
                 if response.code == '0':
                     if flag == 'true':
                         status = 'active'
                     else:
                         status = 'inactive'
                     t_online_info_lazada_detail.objects.filter(
                         SellerSku__in=v).update(Status=status)
                 new_messages[k] = str(response.code)
     else:
         xml_one = '<?xml version="1.0" encoding="UTF-8"?><Request><Product><Skus><Sku><SellerSku>%s</SellerSku><active>%s</active></Sku></Skus></Product></Request>' % (
             SellerSku, flag)
         request.add_api_param('payload', xml_one)
         response = client.execute(request, access_token)
         if response.code == '0':
             if flag == 'true':
                 status = 'active'
             else:
                 status = 'inactive'
             t_online_info_lazada_detail.objects.filter(
                 SellerSku__exact=SellerSku).update(Status=status)
             new_messages['success'] = SellerSku
     return new_messages
コード例 #7
0
ファイル: lazada_test.py プロジェクト: yourant/ur_cleaner
import lazop

appkey = '100692'
app_secret = 'SyqajhckYEjNHe77LOnFvgpXOiGJ6Csg'

client = lazop.LazopClient(f"https://auth.lazada.com/rest", f"{appkey}",
                           f"{app_secret}")
request = lazop.LazopRequest('/auth/token/create')
request.add_api_param('code', '0_100692_jPT1Rh8azmUSvGFpkY8qD5784749')
response = client.execute(request)
print(response)
コード例 #8
0
    def get_products(self, ):
        cur = self.cur
        for k, v in self.new_dic.items():
            sum = 0
            while True:
                client = lazop.LazopClient(
                    v.split(",")[2], self.appkey, self.appSecret)
                request = lazop.LazopRequest('/products/get', 'GET')
                request.add_api_param('filter', 'all')
                request.add_api_param('offset', str(sum))
                request.add_api_param('limit', '300')
                request.add_api_param('options', '1')
                response = client.execute(request, v.split(",")[0])
                try:
                    products_info = response.body['data']['products']
                except:
                    sum = sum + 100
                    continue
                count = len(products_info)
                #TODO
                lis = []
                for pro_info in products_info:
                    item_id = pro_info.get('item_id')
                    attributes = pro_info.get('attributes')
                    name = attributes.get('name')
                    brand = attributes.get('brand')
                    warranty_type = attributes.get('warranty_type')
                    dr = re.compile(r'<[^>]+>', re.S)
                    try:
                        short_description = dr.sub(
                            '', attributes.get('short_description'))
                    except:
                        short_description = ''
                    model = attributes.get('model')
                    try:
                        description = dr.sub('', attributes.get('description'))
                    except:
                        description = ''
                    primary_category = pro_info.get('primary_category')
                    lis.append([
                        item_id,
                        v.split(",")[1], k, name, brand, warranty_type,
                        short_description, model, description,
                        primary_category,
                        datetime.datetime.now(), 1,
                        v.split(",")[1], k, ` name `, brand, warranty_type,
                        short_description, model, description,
                        primary_category,
                        datetime.datetime.now(), 1
                    ])

                    skus = pro_info.get('skus')
                    lis2 = []
                    for skus_info in skus:
                        if len(skus) == 1:
                            color_family = attributes.get('color_family')
                        else:
                            color_family = skus_info.get('color_family')
                        package_width = skus_info.get('package_width')
                        special_from_time = skus_info.get('special_from_time')
                        Available = skus_info.get('Available')
                        compatible_variation = skus_info.get(
                            '_compatible_variation_')
                        package_length = skus_info.get('package_length')
                        fulfillmentStock = skus_info.get('fulfillmentStock')
                        Status = skus_info.get('Status')
                        SkuId = skus_info.get('SkuId')
                        Url = skus_info.get('Url')
                        price = skus_info.get('price')
                        special_price = skus_info.get('special_price')
                        package_weight = skus_info.get('package_weight')
                        nonsellableStock = skus_info.get('nonsellableStock')
                        package_height = skus_info.get('package_height')
                        package_content = skus_info.get('package_content')
                        special_to_time = skus_info.get('special_to_time')
                        ReservedStock = skus_info.get('ReservedStock')
                        SellerSku = skus_info.get('SellerSku')
                        special_from_date = skus_info.get('special_from_date')
                        ShopSku = skus_info.get('ShopSku')
                        special_to_date = skus_info.get('special_to_date')
                        AllocatedStock = skus_info.get('AllocatedStock')
                        Images = str(skus_info.get('Images'))
                        quantity = skus_info.get('quantity')
                        lis2.append([
                            item_id, ShopSku, color_family, package_width,
                            special_from_time, Available, compatible_variation,
                            package_length, fulfillmentStock, Status, SkuId,
                            Url, price, special_price, package_weight,
                            nonsellableStock, package_height, package_content,
                            special_to_time, ReservedStock, SellerSku,
                            special_from_date, special_to_date, AllocatedStock,
                            Images, quantity, color_family, package_width,
                            special_from_time, Available, compatible_variation,
                            package_length, fulfillmentStock, Status, SkuId,
                            Url, price, special_price, package_weight,
                            nonsellableStock, package_height, package_content,
                            special_to_time, ReservedStock, SellerSku,
                            special_from_date, special_to_date, AllocatedStock,
                            Images, quantity
                        ])
                    sql2 = 'INSERT INTO t_online_info_lazada_detail (item_id,ShopSku,color_family,package_width,special_from_time,Available,compatible_variation,package_length,fulfillmentStock,Status,SkuId,Url,price,special_price,package_weight,nonsellableStock,package_height,package_content,special_to_time,ReservedStock,SellerSku,special_from_date,special_to_date,AllocatedStock,Images,quantity) VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)' \
                           ' on duplicate key update color_family = %s,package_width=%s,special_from_time=%s,Available=%s,compatible_variation=%s,package_length=%s,fulfillmentStock=%s,Status=%s,SkuId=%s,Url=%s,price=%s,special_price=%s,package_weight=%s,nonsellableStock=%s,package_height=%s,package_content=%s,special_to_time=%s,ReservedStock=%s,SellerSku=%s,special_from_date=%s,special_to_date=%s,AllocatedStock=%s,Images=%s,quantity=%s;'
                    cur.executemany(sql2, lis2)
                    cur.execute("commit;")
                    lis2 = []

                sql = 'INSERT INTO t_online_info_lazada (item_id,shopname,site,`name`,brand,warranty_type,short_description,model,description,primary_category,updatetime,refresh_status) VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s) on duplicate key update shopname =%s,site=%s,`name`=%s,brand=%s,warranty_type=%s,short_description=%s,model=%s,description=%s,primary_category=%s,updatetime=%s,refresh_status=%s;'
                cur.executemany(sql, lis)
                cur.execute("commit;")
                lis = []

                if count < 300:
                    sum = sum + count
                    print '>>>>>>>>>>>>>>>>>>{}站点抓取结束,总记录为{}条'.format(k, sum)
                    break
                sum = sum + 300
                print '>>>>>>>>>>>>>>>>>已抓取{}站点{}条产品信息'.format(k, sum)
            sql_u1 = 'UPDATE t_online_info_lazada SET status = 2 WHERE refresh_status = 0 AND shopname = "%s" AND site = "%s"' % (
                v.split(",")[1].strip(), k)  # 未刷新的置为异常
            sql_u2 = 'UPDATE t_online_info_lazada SET refresh_status = 0'
            cur.execute(sql_u1)
            cur.execute(sql_u2)
            cur.execute("commit;")
        self.conn.close()
コード例 #9
0
    def get_products_by_sellersku(self, site, seller_sku_list):
        cur = self.cur
        seller_sku_list = json.dumps(seller_sku_list)
        url = self.new_dic[site.strip()].split(',')[2]
        access_token = self.new_dic[site.strip()].split(',')[0]
        shopname = self.new_dic[site.strip()].split(',')[1]
        client = lazop.LazopClient(url, self.appkey, self.appSecret)
        request = lazop.LazopRequest('/products/get', 'GET')
        request.add_api_param('filter', 'all')
        request.add_api_param('limit', '300')
        request.add_api_param('sku_seller_list', seller_sku_list)
        response = client.execute(request, access_token)
        if response.code == '0':
            try:
                products_info = response.body['data']['products']
            except:
                return 'false'
            count = len(products_info)
            lis = []
            for pro_info in products_info:
                item_id = pro_info.get('item_id')
                attributes = pro_info.get('attributes')
                name = attributes.get('name')
                brand = attributes.get('brand')
                warranty_type = attributes.get('warranty_type')
                dr = re.compile(r'<[^>]+>', re.S)
                try:
                    short_description = dr.sub(
                        '', attributes.get('short_description'))
                except:
                    short_description = ''
                model = attributes.get('model')
                try:
                    description = dr.sub('', attributes.get('description'))
                except:
                    description = ''
                primary_category = pro_info.get('primary_category')
                lis.append([
                    item_id, shopname, site, name, brand, warranty_type,
                    short_description, model, description, primary_category,
                    shopname, site, ` name `, brand, warranty_type,
                    short_description, model, description, primary_category
                ])

                skus = pro_info.get('skus')
                # print '-----------------长度-------{}'.format(len(skus))
                lis2 = []
                for skus_info in skus:
                    if len(skus) == 1:
                        color_family = attributes.get('color_family')
                    else:
                        color_family = skus_info.get('color_family')
                    package_width = skus_info.get('package_width')
                    special_from_time = skus_info.get('special_from_time')
                    Available = skus_info.get('Available')
                    compatible_variation = skus_info.get(
                        '_compatible_variation_')
                    package_length = skus_info.get('package_length')
                    fulfillmentStock = skus_info.get('fulfillmentStock')
                    Status = skus_info.get('Status')
                    SkuId = skus_info.get('SkuId')
                    Url = skus_info.get('Url')
                    price = skus_info.get('price')
                    special_price = skus_info.get('special_price')
                    package_weight = skus_info.get('package_weight')
                    nonsellableStock = skus_info.get('nonsellableStock')
                    package_height = skus_info.get('package_height')
                    package_content = skus_info.get('package_content')
                    special_to_time = skus_info.get('special_to_time')
                    ReservedStock = skus_info.get('ReservedStock')
                    SellerSku = skus_info.get('SellerSku')
                    special_from_date = skus_info.get('special_from_date')
                    ShopSku = skus_info.get('ShopSku')
                    special_to_date = skus_info.get('special_to_date')
                    AllocatedStock = skus_info.get('AllocatedStock')
                    Images = str(skus_info.get('Images'))
                    quantity = skus_info.get('quantity')
                    lis2.append([
                        item_id, ShopSku, color_family, package_width,
                        special_from_time, Available, compatible_variation,
                        package_length, fulfillmentStock, Status, SkuId, Url,
                        price, special_price, package_weight, nonsellableStock,
                        package_height, package_content, special_to_time,
                        ReservedStock, SellerSku, special_from_date,
                        special_to_date, AllocatedStock, Images, quantity
                    ])
                t_online_info_lazada_detail.objects.filter(
                    item_id=item_id).delete()
                sql2 = 'INSERT INTO t_online_info_lazada_detail (item_id,ShopSku,color_family,package_width,special_from_time,Available,compatible_variation,package_length,fulfillmentStock,Status,SkuId,Url,price,special_price,package_weight,nonsellableStock,package_height,package_content,special_to_time,ReservedStock,SellerSku,special_from_date,special_to_date,AllocatedStock,Images,quantity) VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s);'
                cur.executemany(sql2, lis2)
                cur.execute("commit;")
                lis2 = []
            sql = 'INSERT INTO t_online_info_lazada (item_id,shopname,site,`name`,brand,warranty_type,short_description,model,description,primary_category) VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s) on duplicate key update shopname =%s,site=%s,`name`=%s,brand=%s,warranty_type=%s,short_description=%s,model=%s,description=%s,primary_category=%s;'
            cur.executemany(sql, lis)
            cur.execute("commit;")
            return 'success'
        else:
            return 'false'
        self.conn.close()
コード例 #10
0
import json

import lazop


url=''

app_key=''
app_secret=''
appkey =app_key
appSecret=app_secret

client = lazop.LazopClient('https://api.lazada.vn/rest',appkey,appSecret)
request = lazop.LazopRequest('/category/attributes/get','GET')
request.add_api_param('primary_category_id', '6396')
response = client.execute(request)
print(response.type)
print(json.dumps(response.body,ensure_ascii=False))


コード例 #11
0
# -*- coding: utf-8 -*-

import lazop

# params 1 : gateway url
# params 2 : appkey
# params 3 : appSecret
client = lazop.LazopClient('https://api.lazada.test/rest', '${appKey}', '${appSecret}')

# create a api request set GET mehotd
# default http method is POST
request = lazop.LazopRequest('/mock/api/get','GET')

# simple type params ,Number ,String
request.add_api_param('api_id','1')

response = client.execute(request)
#response = client.execute(request,access_token)

# response type nil,ISP,ISV,SYSTEM
# nil :no error
# ISP : API Service Provider Error
# ISV : API Request Client Error
# SYSTEM : Lazop platform Error
print(response.type)

# response code, 0 is no error
print(response.code)

# response error message
print(response.message)