需求背景

测试方案

一次性先跑个一万条公司记录,获取线上高级搜索接口返回值中的默认第一个公司的经纬度值,并和 Hadoop 平台上查询到的的这一万条公司的经纬度值进行对比,确认是否有不一样的地方,不一样的要排查是线上的经纬度不对,还是数据部门在清洗数据时获取的经纬度本身就有问题。

代码实践

import requests

def companyLocation():

    companylist = open("D:\QCC_KzzApiAutomation\DataSource\company.text", encoding='utf-8')
    for line in companylist.readlines():
        data = {
            "searchKey": line
        }
        baseUrl = "http://XXX.XXX.com/api/ECILocal/SearchAdvance?"
        resp = requests.get(baseUrl, params=data)
        ressp = resp.json()
        try:
            # print("公司ID:", ressp["Result"][0]["KeyNo"], "公司名称:", ressp["Result"][0]["Name"])
            # print("经纬度:", ressp["Result"][0]["X"], ressp["Result"][0]["Y"])
            id = ressp["Result"][0]["KeyNo"]
            companyName = ressp["Result"][0]["Name"]
            longitude = ressp["Result"][0]["X"]
            latitude = ressp["Result"][0]["Y"]
            string = ''.join((" ", str(id), " ", companyName, " ", str(longitude), ",", str(latitude), "\n"))
            print(string)

            with open("正确经纬度的公司信息.text", "a", encoding="utf-8") as fp:
                string = ''.join((" ", str(id), " ", companyName, " ", str(longitude), ",", str(latitude), "\n"))
                fp.write(string)

        except KeyError:
            with open("错误经纬度的公司信息.text", "a", encoding="utf-8") as fp:
                string = ''.join(("公司ID: ", str(id), " 公司名称: ", companyName, "\n"))
                fp.write(string)
        continue



if __name__ == '__main__':
    companyLocation()

数据比对


↙↙↙阅读原文可查看相关链接,并与作者交流