How to use parse_data method in yandex-tank

Best Python code snippet using yandex-tank

__init__.py

Source:__init__.py Github

copy

Full Screen

1#2# -*- coding: utf-8 -*-3# -*- mode:python ; tab-width:4 -*- ex:set tabstop=4 shiftwidth=4 expandtab: -*-4#5# MPX Trackinfo6# (C) 2008 M. Derezynski7#8import time9import urllib10import urllib211import xml.dom.minidom12import mpxapi.lastfm.model13class TrackTopTags():14 def __init__(self, artist, title):15 self.artist = artist16 self.title = title17 self.parse_elmt = None 18 self.parse_data = {}19 self.parse_tags = []20 self.countdown = 10021 def iterate(self, dom):22 for node in dom.childNodes:23 if node.nodeType == node.ELEMENT_NODE:24 if node.nodeName == "tag":25 if "name" in self.parse_data:26 27 model = mpxapi.lastfm.model.TrackTopTag()28 model.setName(self.parse_data["name"])29 30 if "count" in self.parse_data:31 model.setCount(int(float(self.parse_data["count"])))32 else:33 model.setCount(self.countdown)34 self.countdown = self.countdown - 135 model.setUrl(self.parse_data["url"])36 self.parse_tags.append(model)37 self.parse_data = {} 38 self.parse_elmt = node.nodeName39 self.parse_data[node.nodeName] = ""40 elif node.nodeType == node.TEXT_NODE:41 if self.parse_elmt:42 self.parse_data[self.parse_elmt] = self.parse_data[self.parse_elmt] + node.nodeValue.strip()43 self.iterate(node)44 45 def get(self):46 try:47 req = "http://ws.audioscrobbler.com/1.0/track/%s/%s/toptags.xml" % (urllib.quote(self.artist), urllib.quote(self.title))48 handle = urllib2.urlopen(req)49 dom = xml.dom.minidom.parse(handle)50 handle.close()51 self.iterate(dom)52 except Exception, e:53 print "TrackTopTags: " + str(e)54 return self.parse_tags55class ArtistTopTags():56 def __init__(self, artist):57 self.artist = artist58 self.parse_elmt = None 59 self.parse_data = {}60 self.parse_tags = []61 def iterate(self, dom):62 for node in dom.childNodes:63 if node.nodeType == node.ELEMENT_NODE:64 if node.nodeName == "tag":65 if "name" in self.parse_data:66 67 model = mpxapi.lastfm.model.ArtistTopTag()68 model.setName(self.parse_data["name"])69 model.setCount(int(float(self.parse_data["count"])))70 model.setUrl(self.parse_data["url"])71 self.parse_tags.append(model)72 self.parse_data = {} 73 self.parse_elmt = node.nodeName74 self.parse_data[node.nodeName] = ""75 elif node.nodeType == node.TEXT_NODE:76 if self.parse_elmt:77 self.parse_data[self.parse_elmt] = self.parse_data[self.parse_elmt] + node.nodeValue.strip()78 self.iterate(node)79 80 def get(self):81 try:82 req = "http://ws.audioscrobbler.com/1.0/artist/%s/toptags.xml" % urllib.quote(self.artist)83 handle = urllib2.urlopen(req)84 dom = xml.dom.minidom.parse(handle)85 handle.close()86 self.iterate(dom)87 except Exception, e:88 print "ArtistTopTags: " + str(e)89 return self.parse_tags90class SimilarTracks():91 def __init__(self, artist, title):92 self.artist = artist93 self.title = title94 self.tracks = []95 def iterate2(self, dom):96 for node in dom.childNodes:97 if node.nodeType == node.ELEMENT_NODE:98 self.parse_elmt = "artist." + node.nodeName99 self.parse_data[self.parse_elmt] = ""100 elif node.nodeType == node.TEXT_NODE:101 if self.parse_elmt:102 self.parse_data[self.parse_elmt] = self.parse_data[self.parse_elmt] + node.nodeValue.strip()103 self.iterate2(node)104 def iterate1(self, dom):105 for node in dom.childNodes:106 if node.nodeType == node.ELEMENT_NODE:107 if node.nodeName == "artist":108 109 self.iterate2(node)110 111 else:112 self.parse_elmt = node.nodeName113 self.parse_data[self.parse_elmt] = ""114 elif node.nodeType == node.TEXT_NODE:115 if self.parse_elmt:116 self.parse_data[self.parse_elmt] = self.parse_data[self.parse_elmt] + node.nodeValue.strip()117 self.iterate1(node)118 119 def iterate(self, dom):120 for node in dom.childNodes:121 if node.nodeType == node.ELEMENT_NODE:122 if node.nodeName == "track":123 self.parse_elmt = None 124 self.parse_data = {}125 self.iterate1(node)126 model = mpxapi.lastfm.model.SimilarTrack()127 artist = mpxapi.lastfm.model.SimilarTrackArtist()128 artist.setName(self.parse_data["artist.name"])129 artist.setUrl(self.parse_data["artist.url"])130 model.setArtist(artist)131 model.setName(self.parse_data["name"])132 model.setMatch(float(self.parse_data["match"]))133 model.setUrl(self.parse_data["url"])134 model.setStreamable(self.parse_data["streamable"])135 self.tracks.append(model)136 self.parse_elmt = node.nodeName137 self.iterate(node)138 139 def get(self):140 try:141 req = "http://ws.audioscrobbler.com/1.0/track/%s/%s/similar.xml" % (urllib.quote(self.artist), urllib.quote(self.title))142 handle = urllib2.urlopen(req)143 dom = xml.dom.minidom.parse(handle)144 handle.close()145 self.iterate(dom)146 except Exception, e:147 print "SimilarTracks: " + str(e)148 return self.tracks149class UserTopTracks():150 def __init__(self, user):151 self.user = user152 self.tracks = []153 def iterate1(self, dom):154 for node in dom.childNodes:155 if node.nodeType == node.ELEMENT_NODE:156 if node.nodeName == "artist":157 self.parse_data["artist@mbid"] = node.getAttribute("mbid")158 self.parse_elmt = node.nodeName159 self.parse_data[self.parse_elmt] = ""160 elif node.nodeType == node.TEXT_NODE:161 if self.parse_elmt:162 self.parse_data[self.parse_elmt] = self.parse_data[self.parse_elmt] + node.nodeValue.strip()163 self.iterate1(node)164 def iterate(self, dom):165 for node in dom.childNodes:166 if node.nodeType == node.ELEMENT_NODE:167 if node.nodeName == "track":168 self.parse_data = {}169 self.parse_elmt = None170 self.iterate1(node)171 model = mpxapi.lastfm.model.UserTopTrack()172 model.setArtist(self.parse_data["artist"])173 model.setArtistMBID(self.parse_data["artist@mbid"])174 model.setName(self.parse_data["name"])175 model.setMBID(self.parse_data["mbid"])176 model.setPlaycount(self.parse_data["playcount"])177 model.setUrl(self.parse_data["url"])178 self.tracks.append(model)179 self.iterate(node)180 181 def get(self):182 try:183 req = "http://ws.audioscrobbler.com/1.0/user/%s/toptracks.xml" % urllib.quote(self.user)184 handle = urllib2.urlopen(req)185 dom = xml.dom.minidom.parse(handle)186 handle.close()187 self.iterate(dom)188 except Exception, e:189 print "UserTopTracks: " + str(e)190 return self.tracks191class SimilarArtists():192 def __init__(self, artist):193 self.artist = artist194 self.artists = []195 def iterate1(self, dom):196 for node in dom.childNodes:197 if node.nodeType == node.ELEMENT_NODE:198 self.parse_elmt = node.nodeName199 self.parse_data[self.parse_elmt] = ""200 elif node.nodeType == node.TEXT_NODE:201 if self.parse_elmt:202 self.parse_data[self.parse_elmt] = self.parse_data[self.parse_elmt] + node.nodeValue.strip()203 self.iterate1(node)204 def iterate(self, dom):205 for node in dom.childNodes:206 if node.nodeType == node.ELEMENT_NODE:207 if node.nodeName == "artist":208 self.parse_data = {}209 self.parse_elmt = None 210 self.iterate1(node)211 model = mpxapi.lastfm.model.SimilarArtist()212 model.setName(self.parse_data["name"])213 model.setMBID(self.parse_data["mbid"])214 model.setMatch(float(self.parse_data["match"]))215 model.setUrl(self.parse_data["url"])216 model.setImageSmall(self.parse_data["image_small"])217 model.setImage(self.parse_data["image"])218 model.setStreamable(self.parse_data["streamable"])219 self.artists.append(model)220 self.iterate(node)221 222 def get(self):223 try:224 req = "http://ws.audioscrobbler.com/1.0/artist/%s/similar.xml" % urllib.quote(self.artist)225 handle = urllib2.urlopen(req)226 dom = xml.dom.minidom.parse(handle)227 handle.close()228 self.iterate(dom)229 except Exception, e:230 print "SimilarArtists: " + str(e)231 232 233 return self.artists234class TagTopArtists():235 def __init__(self, tag):236 self.tag = tag237 self.artists = []238 def iterate1(self, dom):239 for node in dom.childNodes:240 if node.nodeType == node.ELEMENT_NODE:241 self.parse_elmt = node.nodeName242 self.parse_data[self.parse_elmt] = ""243 elif node.nodeType == node.TEXT_NODE:244 if self.parse_elmt:245 self.parse_data[self.parse_elmt] = self.parse_data[self.parse_elmt] + node.nodeValue.strip()246 self.iterate1(node)247 def iterate(self, dom):248 for node in dom.childNodes:249 if node.nodeType == node.ELEMENT_NODE:250 if node.nodeName == "artist":251 self.parse_data = {}252 self.parse_elmt = None253 self.parse_data["artist@name"] = node.getAttribute("name")254 self.parse_data["artist@count"] = int(float(node.getAttribute("count")))255 #FIXME: Parse streamable256 self.iterate1(node)257 model = mpxapi.lastfm.model.TagTopArtist()258 model.setName(self.parse_data["artist@name"])259 model.setCount(self.parse_data["artist@count"])260 model.setMBID(self.parse_data["mbid"])261 model.setUrl(self.parse_data["url"])262 model.setThumbnail(self.parse_data["thumbnail"])263 model.setImage(self.parse_data["image"])264 self.artists.append(model)265 self.iterate(node)266 267 def get(self):268 try:269 req = "http://ws.audioscrobbler.com/1.0/tag/%s/topartists.xml" % urllib.quote(self.tag)270 handle = urllib2.urlopen(req)271 dom = xml.dom.minidom.parse(handle)272 handle.close()273 self.iterate(dom)274 except Exception, e:275 print "TagTopArtists: " + str(e)...

Full Screen

Full Screen

JSON_Parser.py

Source:JSON_Parser.py Github

copy

Full Screen

1from tweepy import Stream2from tweepy import OAuthHandler3from tweepy.streaming import StreamListener4import json, csv5import os6nameFile = open('names.txt', 'w', encoding = 'utf-8')7nameFile.close()8textFile = open('text.txt', 'w', encoding = 'utf-8')9textFile.close()10urlFile = open('tweet_url.txt', 'w', encoding = 'utf-8')11urlFile.close()12longitudeFile = open('longitude.txt', 'w', encoding = 'utf-8')13longitudeFile.close()14latitudeFile = open('latitude.txt', 'w', encoding = 'utf-8')15latitudeFile.close()16counter = 017# data_File = open('raw_twitDB3.json')18with open('raw_twitDB3.json') as dataLine:19 print("Loading file...")20 for line in dataLine:21 # print(line)22 if len(line) > 1:23 # print("this: " + str(len(line)))24 parse_data = json.loads(line)25 # print(parse_data['truncated'])26 twitter_handle = (parse_data['user']['name'])27 nameFile = open('names.txt', 'a', encoding = 'utf-8')28 twitter_handle = str(twitter_handle)29 nameFile.write(twitter_handle)30 nameFile.write('\n')31 nameFile.close()32 # if parse_data['truncated'] == 'false'33 if parse_data.get('extended_tweet'):34 if parse_data.get('extended_tweet').get('full_text'):35 user_text = parse_data['extended_tweet']['full_text']36 # print(user_text)37 else:38 user_text = parse_data['text']39 elif parse_data.get('retweeted_status'):40 if parse_data.get('retweeted_status').get('extended_tweet'):41 if parse_data.get('retweeted_status').get('extended_tweet').get('full_text'):42 user_text = parse_data['retweeted_status']['extended_tweet']['full_text']43 else:44 user_text = parse_data['text']45 else:46 user_text = parse_data['text']47 else:48 user_text = parse_data['text']49 combined_line = "".join(user_text.splitlines())50 textFile = open('text.txt', 'a', encoding = 'utf-8')51 textFile.write(combined_line)52 textFile.write('\n')53 textFile.close()54 if parse_data.get('entities'):55 if parse_data.get('entities').get('urls'):56 if parse_data.get('entities').get('urls')[0].get('expanded_url'):57 tweet_url = parse_data['entities']['urls'][0]['expanded_url']58 urlFile = open('tweet_url.txt', 'a')59 base_url = "https://twitter.com/i/web/status/"60 if parse_data.get('id'):61 tweet_id = parse_data['id']62 combined_id = base_url + str(tweet_id)63 if tweet_url == combined_id:64 tweet_url = "No urls"65 urlFile.write(tweet_url)66 urlFile.write("\n")67 urlFile.close()68 else:69 tweet_url = "No urls"70 urlFile = open('tweet_url.txt', 'a')71 urlFile.write(tweet_url)72 urlFile.write("\n")73 urlFile.close()74 if parse_data.get('place'):75 if parse_data.get('place').get('bounding_box'):76 if parse_data.get('place').get('bounding_box').get('coordinates'):77 geo_location1 = parse_data['place']['bounding_box']['coordinates'][0][1][0]78 geo_location2 = parse_data['place']['bounding_box']['coordinates'][0][1][1]79 longitudeFile = open('longitude.txt', 'a')80 latitudeFile = open('latitude.txt', 'a')81 longitudeFile.write(str(geo_location1))82 latitudeFile.write(str(geo_location2))83 longitudeFile.write("\n")84 latitudeFile.write("\n")85 longitudeFile.close()...

Full Screen

Full Screen

day01.py

Source:day01.py Github

copy

Full Screen

1def part_1(parse_data):2 inc_ct = 03 last_val = parse_data[0]4 for val in parse_data:5 if val > last_val:6 inc_ct +=1 7 last_val = val8 return inc_ct9def saatvik_solution(parse_data):10 count = 011 for i in range(3, len(parse_data)):12 if parse_data[i] > parse_data[i-3]:13 count += 114 return count15def arnav_soln(parse_data):16 count = -117 last_val = parse_data[0]18 for i in range(1, len(parse_data) - 2):19 suma = parse_data[i] + parse_data[i+1] + parse_data[i+2]20 if suma > last_val:21 count += 122 last_val = suma23 return count24if __name__ == '__main__':25 parse_data = [int(v) for v in open("data.txt").readlines()]26 print("Part 1:")27 print(part_1(parse_data))28 print("Part 2:")29 print(saatvik_solution(parse_data))...

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