Best Python code snippet using avocado_python
Commercial.py
Source:Commercial.py
...121def put_hash_in_a_file(hash, filename):122 with open(filename+ ".txt", "w") as txt_file:123 for item in hash:124 txt_file.write("%s, " % item)125def read_hash_from_file(filename):126 with open(filename+ ".txt", "r") as txt_file:127 hashcode = txt_file.read().split(', ')128 del hashcode[-1]129 return hashcode130def find_commercial(filename):131 hash1 = read_hash_from_file("output_female")132 hash2 = read_hash_from_file("output_speech")133 hash3 = read_hash_from_file("output_audio")134 hash_comp = get_sound(filename)135 const1 = find_constellations(hash1, hash_comp)136 const2 = find_constellations(hash2, hash_comp)137 const3 = find_constellations(hash3, hash_comp)138 if const1 >= 3 or const2 >= 3 or const3 >= 3:139 print("Реклама еÑÑÑ")140 else:141 print("Ð ÐµÐºÐ»Ð°Ð¼Ñ Ð½ÐµÑ")142find_commercial("male")143#put_hash_in_a_file(get_sound("speech"), "output_audio")144#find_constellations(get_sound("female"), get_sound("mix3"))...
magnet.py
Source:magnet.py
...8 gir = gi.record_by_addr(ip_address)9 if gir != None:10 location = [gir['country_name'], gir['city']]11 return location12def read_hash_from_file(line):13 #Read a line from the file and return a hash.14 h = line.split('|')15 torrent_hash = h[len(h)-1]16 return torrent_hash17def total_hashes(f):18 #Read file and return how many hashes there are19 return num_hashes20def peer_info(handle):21 #Take the torrent handle and return peer information22 return 023def create_magnet_url(torrent_hash):24 link = "magnet:?xt=urn:btih:%s&tr=udp%%3A%%2F%%2Ftracker.openbittorrent.com%%3A80&tr=udp%%3A%%2F%%2Ftracker.publicbt.com%%3A80" % torrent_hash25 return link26def create_session():27 ses = lt.session()28 return ses29def create_handle(ses,link,params):30 handle = lt.add_magnet_uri(ses, link, params)31 return handle32def get_metadata(handle):33 print 'downloading metadata...'34 handle.metadata()35 #while (not handle.has_metadata()):36 # print err37 # time.sleep(1)38 # err = err + 139 print 'got metadata, starting torrent download...'40 #return handle.metadata()41def get_tracker_information(handle):42 #Get tracker information43 for t in handle.trackers():44 print t45def get_file_information(handle):46 #Get file information47 print "##### FILE INFO #####"48 files = handle.get_torrent_info()49 print "Total Files:%d" % files.num_files()50 for f in files.files():51 print "File Path:%s" % f.path52 print "File Offset:%s" % f.offset53 print "File Size:%f" % (f.size/1024)54def get_torrent_summary_information(handle):55 #Get torrent summary information56 status = handle.status()57 print "Peers:", status.list_peers58 print "Num Peers:", status.num_peers59 print "Seeds:", status.list_seeds60 print "Num Seeds:", status.num_seeds61 print "Active:", status.active_time62 print "All Time Downloaded:", status.all_time_download63 print "File Information", get_file_information(handle)64def get_peer_details(handle):65 #Get peer information66 pe = handle.get_peer_info()67 print "Peers: %d" % len(pe)68 for p in handle.get_peer_info():69 print "Client:%s IP:%s Country:%s Progress:%s" % (p.client,p.ip,ip_location(p.ip[0]),p.downloading_total)70 #print p.flags71 #print p.down_speed72 #print p.last_active73 #print p.downloading_progress74 #print p.pieces75 #print p.rtt76 #print p.total_download77 #print p.total_upload78def download_torrent(handle):79 while (handle.status().state != lt.torrent_status.seeding):80 print '%d %% done' % (handle.status().progress*100)81 for p in handle.get_peer_info():82 print p.ip83 print p.flags84 print p.down_speed85 print p.last_active86 print p.downloading_progress87 #print p.pieces88 print p.rtt89 print p.total_download90 print p.total_upload91params = { 'save_path': './'}92num_tries = 393torrent_file = 'complete'94pickle_file = 'top100.bin'95use_pickle = 1 96if pickle_file:97 f = pickle.load(open(pickle_file))98elif (not pickle_file):99 f = open(torrent_file,'r')100for line in f:101 #print line102 tries = 0103 # Create a session, get a handle, grab a hash and get peers104 if pickle_file:105 link = line['downloadLink']106 elif (not pickle_file):107 my_hash = read_hash_from_file(line)108 link = create_magnet_url(my_hash)109 print link110 ses = create_session()111 handle = create_handle(ses,link,params)112 while tries < num_tries:113 # get_metadata(handle)114 print "Calling metadata"115 handle.has_metadata()116 time.sleep(30) #Give metadata 10s to timeout117 if (not handle.has_metadata()):118 tries = tries + 1119 else:120 print "Boom got metadata"121 #break...
hash_api.py
Source:hash_api.py
...5HASH_FILE = "backend/resources/.last-hash"6if not os.path.exists(HASH_FILE):7 f: IO = open(HASH_FILE, "x")8 f.close()9def read_hash_from_file() -> dict:10 data: dict = {}11 try:12 with open(HASH_FILE, "rb") as rf:13 data = pickle.load(rf)14 except EOFError as e:15 logging.error("Hash file is empty!")16 data["last_hash"] = None17 return data18def save_hash_to_file(sha: str):19 with open(HASH_FILE, "wb") as sf:20 pickle.dump({"last_hash": sha}, sf)21def check_hash_same(new_hash: str):22 old_hash: str = read_hash_from_file()["last_hash"]...
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!!