How to use __cut_name method in yandex-tank

Best Python code snippet using yandex-tank

AmapUtil.py

Source:AmapUtil.py Github

copy

Full Screen

...173 param['key'] = AMAP_KEY174 param['radius'] = 1000175 param['output'] = 'json'176 return param177 def __cut_name(self, name):178 ' 调整地址名称为短格式 '179 if name.find(u"街道") > 0:180 name = name.split(u"街道")[1]181 elif name.find(u"镇") > 0:182 name = name.split(u"镇")[1]183 elif name.find(u"乡") > 0:184 name = name.split(u"乡")[1]185 elif name.find(u"区") > 0:186 name = name.split(u"区")[1]187 return name188 @classmethod189 def getRoads(cls, point):190 pos = str(point.longitude) + ',' + str(point.latitude)191 param = cls().__mk_args(pos)192 param['extensions'] = "all"193 try:194 data = requests.get("http://restapi.amap.com/v3/geocode/regeo", param).json()195 if data['info'] == "OK":196 regeo = data.get("regeocode", {})197 out = []198 # 道路199 for pos in regeo.get("roads", []):200 road = {}201 lng, lat = pos['location'].split(",")202 road['lat'] = lat203 road['lng'] = lng204 road['name'] = pos['name']205 road['distance'] = pos['distance']206 road['direction'] = pos['direction']207 road['type'] = "road"208 out.append(road)209 # 十字路口210 for pos in regeo.get("roadinters", []):211 road = {}212 lng, lat = pos['location'].split(",")213 road['lat'] = lat214 road['lng'] = lng215 road['name'] = pos['first_name']216 road['distance'] = pos['distance']217 road['direction'] = pos['direction']218 road['type'] = "roadinter"219 # out.append(road)220 return out221 else:222 return []223 except Exception, e:224 print e225 return []226 @classmethod227 def getName(cls, point):228 obj = cls()229 pos = str(point.longitude) + ',' + str(point.latitude)230 param = obj.__mk_args(pos)231 try:232 data = requests.get("http://restapi.amap.com/v3/geocode/regeo", param).json()233 if data['info'] == "OK":234 regeo = data.get("regeocode", {})235 return obj.__cut_name(regeo.get('formatted_address', ""))236 else:237 return ""238 except Exception, e:239 print e240 return ""241 @classmethod242 def getNameBatch(cls, points):243 ' 20个一批次调用高德regeo接口,返回地名 '244 obj = cls()245 out = []246 for chunk in chunks(points, 20):247 pos = '|'.join([str(x.longitude) + ',' + str(x.latitude) for x in chunk])248 param = obj.__mk_args(pos)249 param['batch'] = "true"250 try:251 data = requests.get("http://restapi.amap.com/v3/geocode/regeo", param).json()252 if data['info'] == "OK":253 regeos = data.get("regeocodes", {})254 for pos in regeos:255 out.append(obj.__cut_name(pos.get('formatted_address', "")))256 except Exception, e:257 print e258 return out259class AmapBatch():260 def __batch_by_amap(self, urls):261 if not isinstance(urls, list):262 raise ValueError("input urls must be list")263 if len(urls) > 20:264 raise ValueError("at most 20 url one time")265 param = dict()266 param['ops'] = map(lambda url: dict(url=url), urls)267 url = "http://restapi.amap.com/v3/batch?key=" + AMAP_KEY268 headers = {'Content-type': 'application/json'}269 return requests.post(url, data=json.dumps(param), headers=headers).json()...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run yandex-tank automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful