Best Python code snippet using avocado_python
downTXT.py
Source:downTXT.py  
...15import log1617logger = log.Log(config.log_dir, config.log_name)1819def gzip_uncompress(c_data):20	buf = StringIO(c_data)21	f = gzip.GzipFile(mode = 'rb', fileobj = buf)22	try:23		r_data = f.read()24	finally:25		f.close()26	return r_data2728class DownTXT(object):29	getDocInfo = 'https://wenku.baidu.com/api/doc/getdocinfo?callback=cb'30	downDocUrl = 'https://wkretype.bdimg.com/retype/text/'3132	def __init__(self, fileDir, url, info):33		self.fileDir = './' + fileDir + '/'34		self.URL = url35		self.WkInfo = info36		if not os.path.exists(self.fileDir):37			os.mkdir(self.fileDir)3839	def down(self):40		docID = self.URL[self.URL.rfind('/') + 1 : self.URL.find('.html')]41		reqHeader = config.reqHeaderBDWK42		reqHeader['Referer'] = self.URL43		reqHeader['HOST'] = 'wenku.baidu.com'44		# è·åææ¡£ä¿¡æ¯45		# url: https://wenku.baidu.com/api/doc/getdocinfo?callback=cb&doc_id=60108d36336c1eb91a375dd2&t=1524896355038&_=152489635426446		ms = int(time.time() * 1000)47		reqUrl = DownTXT.getDocInfo + '&doc_id=' + docID + '&t=' + str(ms+2000) + '&_=' + str(ms)48		logger.info(reqUrl)49		req = urllib2.Request(reqUrl, headers=reqHeader)50		response = urllib2.urlopen(req)51		res = response.read()52		logger.info('ååºå¤´ä¿¡æ¯ï¼' + str(response.headers))53		#if response.headers['Transfer-Encoding'] == 'chunked':54		#	res = decode_chunked(res)55		if response.headers['Content-Encoding'] == 'gzip':56			res = gzip_uncompress(res)57		logger.info('getDocInfo ååºä¿¡æ¯ï¼ ' + res)58		docInfo = res[res.find('(')+1 : res.rfind(')')]59		docInfo = json.loads(docInfo)60		# è·åææ¡£å
容61		reqUrl = DownTXT.downDocUrl + docID + '?type=txt&callback=cb&pn=1&rn=' + str(self.WkInfo['totalPageNum']) +\62				 '&rsign=' + docInfo['rsign'] + '&_=' + str(ms) + docInfo['md5sum']63		reqHeader['HOST'] = 'wkretype.bdimg.com'64		req = urllib2.Request(reqUrl, headers=reqHeader)65		response = urllib2.urlopen(req)66		res = response.read()67		if response.headers['Content-Encoding'] == 'gzip':68			res = gzip_uncompress(res)69		docContent = res[res.find('(')+1 : res.rfind(')')]70		docContent = json.loads(docContent)71		# ä¿åå
容å°txtæä»¶72		txtFileName = self.fileDir + self.WkInfo['title'] + '.' + self.WkInfo['docType']73		fp = open(txtFileName, 'w')74		for dc in docContent:75			fp.write(dc['parags'][0]['c'])76		fp.close()
...decode_gzip_base64.py
Source:decode_gzip_base64.py  
...1112# æäººé®å¯ææ¯ä»ä¹å å¯ï¼æäººæ³¨æå°æ¯ gzip + base64 , è²ä¼¼æ¯python2ç1314def de_ciper():15    print(gzip_uncompress(base64.b64decode(16        "H4sIAAmhtGAA/2NgZGBg+A8EIBoEWEAMvuDK4pLUXD2n/Pyc1MQ8kBB7bnxZYk5pKgMjIzcAmxcDozUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==")))171819def gzip_uncompress(c_data):20    try:21        buf = BytesIO(c_data)22        print(gzip.GzipFile(mode='rb', fileobj=buf).read())23    except Exception as  e:24        print("uncompress wrong" + e)252627# de_ciper()2829if __name__ == '__main__':3031    txt = de_ciper()
...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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
