示例#1
0
def api(barcode):

    payload = {'status': 'all', 'language': 'TH', 'barcode': [barcode]}

    headers = {
        'Authorization':
        'Token eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJpc3MiOiJzZWN1cmUtYXBpIiwiYXVkIjoic2VjdXJlLWFwcCIsInN1YiI6IkF1dGhvcml6YXRpb24iLCJleHAiOjE1OTQ1MTk4NjMsInJvbCI6WyJST0xFX1VTRVIiXSwiZCpzaWciOnsicCI6InpXNzB4IiwicyI6bnVsbCwidSI6IjI2MGQ2NzNhMjE3MTRmZDIyZTcyNzUxZDI4ZDU2YzM1IiwiZiI6InhzeiM5In19.2-pDB10a9l5V-WedP-bUxSZvtwj3nvxdsKVq6zLkRI9gvW2212ukZ0vSNBTcdtKxBhVAaf8X0m-pdtt1K78gWA',
        'Content-Type': 'application/json'
    }

    # res = requests.post(urls.THAIPOST_API, json=payload, headers=headers, verify=False)
    # staCode = res.status_code

    res = requests.get(urls.THAIPOST_API_2 + barcode)
    staCode = res.status_code

    if staCode == 200:
        js = res.json()

        if js["status"] == 1:
            api = thaipost_adapter.convert(js)

    elif staCode == 500:
        js = res.json()

        if js["status"] == 0 and js["message"] == "Empty data.":
            api = response_template.success(204, "Shipment not found!", None)

    else:
        api = response_template.error(500, "Internal Server Error")

    return api
示例#2
0
def json(info: [], status: [[]]):
    statusDict = {}
    statusDictArr = []

    for i in range(len(status)):
        statusDict = {
            "code": status[i][0],
            "date": status[i][1],
            "detail": status[i][2],
            "province": status[i][3]
        }

        statusDictArr.append(statusDict)

    x = {
        "info": {
            "no": info[0],
            "company": info[1],
            "sender": info[2],
            "receiver": info[3]
        },
        "status": statusDictArr
    }

    return response_template.success(200, "Success", x)
示例#3
0
def web(barcode):
    chrome_options = webdriver.ChromeOptions()
    chrome_options.add_argument('--headless')
    chrome_options.add_argument('--disable-dev-shm-usage')
    chrome_options.add_argument('--no-sandbox')
    chrome_options.binary_location = os.environ.get("GOOGLE_CHROME_BIN")

    CHROMEDRIVER_PATH = 'D:\Python\chromedriver'
    browser = webdriver.Chrome(executable_path=CHROMEDRIVER_PATH,
                               options=chrome_options)
    # browser = webdriver.Chrome(executable_path=os.environ.get("CHROMEDRIVER_PATH"), options=chrome_options)
    # browser.get(urls.FLASH_API + barcode)

    return response_template.success(200, "Flash Web", None)
示例#4
0
def track(barcode: str):   

    company = package_code.company(barcode)
    if company == "thaipost":
        print("Thaipost")
        return thaipost.api(barcode)
    elif company == "flash":
        print("Flash")
        return flash.api(barcode)        
    elif company == "kerry":
        print("Kerry")
        return kerry.api(barcode)
    elif company == "test":
        return package_code.apiTest(barcode)
    else:
        return response_template.success(422, "Unprocessable Entit", None)
示例#5
0
def api(barcode):
    res = requests.get(urls.KERRY_API + barcode + '/th')
    staCode = res.status_code

    if staCode == 200:
        js = res.json()
        err = list(js.keys())[0]

        if err == "error":
            print("[Kerry]: Api error >>", js["error"]["code"])
            api = web(barcode)
        else:
            api = kerry_adapter.convert(js)

    elif staCode == 404:
        api = response_template.success(204, "Shipment not found!", None)

    else:
        api = response_template.error(500, "Internal Server Error")

    return api