コード例 #1
0
def IssueCoupon():
    # 接口的url
    url = "https://apichina.capillarytech-cn.com/api/v1.1/coupon/issue?format=json"
    for i in xrange(1, sheet1.nrows):  # 行数
        series_id = int(sheet1.cell_value(i, 0))
        user_id = int(sheet1.cell_value(i, 1))
        body = "{\"root\":{\"coupon\":[{\"series_id\":\"%s\",\"customer\":{\"id\":\"%s\"}}]}}" % (
            series_id, user_id)
        print(body)
        r = requests.request("post", url, data=body, headers=headers)
        resp = json.loads(r.text)
        #print(resp)
        resp_code = resp["response"]["status"]["code"]
        if resp_code == 200:
            coupon_code = resp["response"]["coupon"]["code"]
            coupon_desc = resp["response"]["coupon"]["description"]
            coupon_valid_till = resp["response"]["coupon"]["valid_till"]
            coupon_discount_value = resp["response"]["coupon"][
                "discount_value"]
            resplist = [
                coupon_code, coupon_desc, coupon_valid_till,
                coupon_discount_value, resp_code
            ]
            print(coupon_code)
            print(coupon_desc)
            print(coupon_valid_till)
            print(coupon_discount_value)
        else:
            print(resp)
            resp_code = resp['response']['status']['code']
            resp_message = resp['response']['status']['message']
            resplist = [resp_code, resp_message]
        start = 3
        writeexcel.write_excel(filename, i, resplist, start)
コード例 #2
0
class FetchTransaction():
    # 接口的header
    #headers = Headers.HEADERS["tnf_demo"]

    def FetchTransactionDetails(cellValues):
        # 接口的url
        url = "https://api.capillarytech.cn.com/v1.1/transaction/get?format=json&number=%s"% cellValues
        r = requests.request("get", url, headers=Headers.HEADERS["tnf_demo"])
        status = r.status_code
        if status != 200:
            print ("\x1b[31mfail: status-> {} {}\x1b[0m".format(status, url))

        resp = json.loads(r.text)
        resp_code = resp["response"]["transactions"]["transaction"][0]["item_status"]["code"]
        resp_message = resp["response"]["transactions"]["transaction"][0]["item_status"]["message"]

        if resp_code== 600 and resp_message == "Transaction retrieved successfully":
            print("\x1b[32mpass: {}\x1b[0m".format(url))
        else:
            print("\x1b[31mfail: {} code: {}, message:{}\x1b[0m".format(url,resp_code,resp_message))
        #assert resp_code== 600 and resp_message == "Transaction retrieved successfully", "failed"
        return resp_code,resp_message

    getdata = readexcel.read_excel()
    sheet1 = getdata.sheet_by_index(0)  # sheet索引从0开始
    #print(sheet1.name, sheet1.nrows, sheet1.ncols)

    for i in xrange(1,sheet1.nrows): #行数
           cellValues = sheet1.cell_value(i,0)
           print(cellValues)
           resp_code,resp_message=FetchTransactionDetails(cellValues)
           print(resp_code,resp_message)
           writeexcel.write_excel(i,resp_code,resp_message)
コード例 #3
0
def DescenteIssueCoupon():
    # 接口的url
    url = "https://api.capillarytech.cn.com/v1.1/coupon/issue?format=json"
    for i in xrange(1, sheet1.nrows):  # 行数
        body = sheet1.cell_value(i, 0)
        print(body)
        r = requests.request("post", url, data=body, headers=headers)
        resp = json.loads(r.text)
        print(resp)
        resp_code = resp["response"]["status"]["code"]
        coupon_code = resp["response"]["coupon"]["code"]
        coupon_desc = resp["response"]["coupon"]["description"]
        coupon_valid_till = resp["response"]["coupon"]["valid_till"]
        coupon_discount_value = resp["response"]["coupon"]["discount_value"]
        resplist = [coupon_code,coupon_desc,coupon_valid_till,coupon_discount_value,resp_code]
        if resp_code == 200:
            print(coupon_code)
            print(coupon_desc)
            print(coupon_valid_till)
            print(coupon_discount_value)
            start=1
            writeexcel.write_excel(filename,i, resplist,start)
        else: print(resp)
コード例 #4
0
class ExportMemberV2():

    filename = "/pythonjulia/files/TNF Demo -- Fetch Transaction1.xls"

    def ExportMemberV2Details(cellValues):
        # 接口的url
        preUrl = Urls.URLS["tnf_demo"]["url"]
        source = Urls.URLS["tnf_demo"]["source"]
        accountId = Urls.URLS["tnf_demo"]["accountId"]
        url = "%sv2/customers/%s?source=%s&accountId=%s" % (preUrl, cellValues,
                                                            source, accountId)
        print(url)
        r = requests.request("get", url, headers=Headers.HEADERS["tnf_demo"])
        resp = json.loads(r.text)
        fields = resp["profiles"][0]["fields"]
        #print(fields)
        resp_bday = ''
        resp_tnflastupdate = ''
        resp_gender = ''
        if "birthday" in fields:
            resp_bday = fields['birthday']
        if "tnflastupdate" in fields:
            resp_tnflastupdate = fields['tnflastupdate']
        if "gender" in fields:
            resp_gender = fields['gender']

        resp_mobile = '',
        resp_externalId = ''
        for i in resp["profiles"][0]["identifiers"]:
            if i["type"] == "mobile":
                resp_mobile = i["value"]
            if i["type"] == "externalId":
                resp_externalId = i["value"]
        resplist = [
            resp_mobile, resp_externalId, resp_bday, resp_tnflastupdate,
            resp_gender
        ]
        return resplist

    getdata = readexcel.read_excel(filename)
    sheet1 = getdata.sheet_by_index(0)  # sheet索引从0开始
    #print(sheet1.name, sheet1.nrows, sheet1.ncols)

    for i in xrange(1, sheet1.nrows):  # 行数
        cellValues = sheet1.cell_value(i, 0)
        #resp_mobile, resp_externalId, resp_bday = ExportMemberV2Details(cellValues)
        outputlist = ExportMemberV2Details(cellValues)
        start = 1
        writeexcel.write_excel(filename, i, outputlist, start)
コード例 #5
0
#!/usr/bin/python
# -*- coding: UTF-8 -*-

from Utilities import readexcel
from Utilities import writeexcel
from xlrd.timemachine import xrange
from Fetch_Member_API_V2.ExportMemberV2_1 import ExportMemberV2_1

filename = "/pythonjulia/files/TNF Demo -- GetCustomerDetailsById.xls"

getdata = readexcel.read_excel(filename)
sheet1 = getdata.sheet_by_index(0)  # sheet索引从0开始
for i in xrange(1, sheet1.nrows):  # 行数
    cellValues = sheet1.cell_value(i, 0)
    outputlist = ExportMemberV2_1.ExportMemberV2_1Details(cellValues)
    start = 1
    writeexcel.write_excel(filename, i, outputlist, start)
コード例 #6
0
def RegisterWeChat():
    # 接口的url
    headers = Headers.HEADERS["tnf_demo_wechat"]
    preUrl = Urls.URLS["tnf_demo"]["url"]
    source = Urls.URLS["tnf_demo"]["source2"]
    getdata = readexcel.read_excel(filename)
    sheet1 = getdata.sheet_by_index(0)  # sheet索引从0开始
    print(sheet1)
    for i in xrange(1, sheet1.nrows):  # 行数
        accountId = sheet1.cell_value(i, 9)
        url = "%sv2/customers?source=%s&accountId=%s" % (preUrl, source,
                                                         accountId)
        print(url)
        email = sheet1.cell_value(i, 0)
        mobile = sheet1.cell_value(i, 1)
        createDateS = sheet1.cell_value(i, 2)
        if createDateS != '':
            createDate = datetimeformat.string_toDatetime(createDateS)
        else:
            createDate = ''
        externalId = sheet1.cell_value(i, 3)
        firstName = sheet1.cell_value(i, 4)
        birthdayS = sheet1.cell_value(i, 5)
        if birthdayS != '':
            birthday = datetimeformat.string_toDate(birthdayS)
        else:
            birthday = ''
        gender = sheet1.cell_value(i, 6)
        openid = sheet1.cell_value(i, 7)

        if birthday != '' and gender != '':
            body = "{\"profiles\":[{\"firstName\":\"%s\",\"fields\":{\"gender\":\"%s\",\"birthday\":\"%s\"},\"identifiers\":[{\"type\":\"wechat\",\"value\":\"%s\"},{\"type\":\"mobile\",\"value\":\"%s\"},{\"type\":\"externalId\",\"value\":\"%s\"},{\"type\":\"email\",\"value\":\"%s\"}],\"commChannels\":[{\"type\":\"wechat\",\"value\":\"%s\",\"primary\":true,\"verified\":true},{\"type\":\"mobile\",\"value\":\"%s\",\"primary\":true,\"verified\":true}]}],\"loyaltyInfo\":{\"loyaltyType\":\"loyalty\",\"attributionV2\": {\"createDate\": \"%s\"}}}" \
                   % (firstName, gender, birthday, openid, mobile, externalId, email, openid, mobile, createDate)
        elif birthday != '' and gender == '':
            body = "{\"profiles\":[{\"firstName\":\"%s\",\"fields\":{\"birthday\":\"%s\"},\"identifiers\":[{\"type\":\"wechat\",\"value\":\"%s\"},{\"type\":\"mobile\",\"value\":\"%s\"},{\"type\":\"externalId\",\"value\":\"%s\"},{\"type\":\"email\",\"value\":\"%s\"}],\"commChannels\":[{\"type\":\"wechat\",\"value\":\"%s\",\"primary\":true,\"verified\":true},{\"type\":\"mobile\",\"value\":\"%s\",\"primary\":true,\"verified\":true}]}],\"loyaltyInfo\":{\"loyaltyType\":\"loyalty\",\"attributionV2\": {\"createDate\": \"%s\"}}}" \
                   % (firstName, birthday, openid, mobile, externalId, email, openid, mobile, createDate)
        elif birthday == '' and gender != '':
            body = "{\"profiles\":[{\"firstName\":\"%s\",\"fields\":{\"gender\":\"%s\"},\"identifiers\":[{\"type\":\"wechat\",\"value\":\"%s\"},{\"type\":\"mobile\",\"value\":\"%s\"},{\"type\":\"externalId\",\"value\":\"%s\"},{\"type\":\"email\",\"value\":\"%s\"}],\"commChannels\":[{\"type\":\"wechat\",\"value\":\"%s\",\"primary\":true,\"verified\":true},{\"type\":\"mobile\",\"value\":\"%s\",\"primary\":true,\"verified\":true}]}],\"loyaltyInfo\":{\"loyaltyType\":\"loyalty\",\"attributionV2\": {\"createDate\": \"%s\"}}}" \
                   % (firstName, gender, openid, mobile, externalId, email, openid, mobile, createDate)
        elif birthday == '' and gender == '':
            body = "{\"profiles\":[{\"firstName\":\"%s\",\"identifiers\":[{\"type\":\"wechat\",\"value\":\"%s\"},{\"type\":\"mobile\",\"value\":\"%s\"},{\"type\":\"externalId\",\"value\":\"%s\"},{\"type\":\"email\",\"value\":\"%s\"}],\"commChannels\":[{\"type\":\"wechat\",\"value\":\"%s\",\"primary\":true,\"verified\":true},{\"type\":\"mobile\",\"value\":\"%s\",\"primary\":true,\"verified\":true}]}],\"loyaltyInfo\":{\"loyaltyType\":\"loyalty\",\"attributionV2\": {\"createDate\": \"%s\"}}}" \
               % (firstName, openid, mobile, externalId, email, openid, mobile, createDate)
        print(body)
        r = requests.request("post",
                             url,
                             data=body.encode('utf-8'),
                             headers=headers)
        print(r)
        resp = json.loads(r.text)
        print(resp)
        if "createdId" in resp and "code" not in resp:
            userid = resp["createdId"]
            outputlist = [userid]
        elif "createdId" in resp and "code" in resp:
            userid = resp["createdId"]
            code = resp["warnings"][0]["code"]
            status = resp["warnings"][0]["status"]
            message = resp["warnings"][0]["message"]
            outputlist = [userid, code, status, message]
        else:
            code = resp["errors"][0]["code"]
            status = resp["errors"][0]["status"]
            message = resp["errors"][0]["message"]
            outputlist = [code, status, message]
        print(outputlist)
        print(len(outputlist))
        start = 11
        writeexcel.write_excel(filename, i, outputlist, start)