Best Python code snippet using avocado_python
download_image.py
Source:download_image.py
...67 for key in sign_list:68 request_url = request_url + urllib.urlencode({key: sign_dict[key]}) + "&"69 request_url = DOMAIN + path + "?" + request_url + "sign=" + sign70 return request_url71def download_image(img_url, path, filename):72 try:73 sock = urllib.urlopen(img_url)74 htmlcode = sock.read()75 sock.close()76 filedir = open(os.path.join(path, filename), "wb")77 filedir.write(htmlcode)78 filedir.close()79 except Exception as err:80 logging.info('open url image error: %s', err)81 # abnormal_log.info('open url image error: %s', err)82def main():83 for line in src_file.readlines():84 line = line.strip('\n').split('\t')85 url = line[7]86 filename = url.split('/')[-1]87 request_url = DOMAIN + url88 print(url)89 # request_url = get_sign(url, EXP)90 rejectcodes = line[2]91 if rejectcodes == '230001001': #é3Dhomeæ·åå¾92 download_image(request_url, './230001001', filename)93 if rejectcodes == '230001002': #æ 注ç®ç§°94 download_image(request_url, './230001002', filename)95 if rejectcodes == '230001003': #åè½é´å称é误96 download_image(request_url, './230001003', filename)97 if rejectcodes == '230001004': #é¢è²é误98 download_image(request_url, './230001004', filename)99 if rejectcodes == '230001005': #æ¹åæ é误100 download_image(request_url, './230001005', filename)101 if rejectcodes == '230001006': #å°é空é´102 download_image(request_url, './230001006', filename)103 if rejectcodes=='230001007': #æ¾ç¤ºä¸å
¨104 download_image(request_url, './230001007', filename)105 if rejectcodes=='230001008': #æ·åå¾ä¿®é¥°106 download_image(request_url, './230001008', filename)107 if rejectcodes=='230001009': #æªç»å¶æ¥¼æ¢¯108 download_image(request_url, './230001009', filename)109 if rejectcodes=='230001010': #åä½å¤§å°ä¸ä¸è´110 download_image(request_url, './230001010', filename)111 if rejectcodes=='230001011': #åéæ°´å°112 download_image(request_url, './230001011', filename)113 if rejectcodes=='230001012': #å°ç»å¶åè½é´114 download_image(request_url, './230001012', filename)115 if rejectcodes=='230001013': #å
¥æ·é¨é误116 download_image(request_url, './230001013', filename)117 if rejectcodes=='230001014': #楼å±é误118 download_image(request_url, './230001014', filename)119 if rejectcodes=='230001015': #è线ç»å¶é误120 download_image(request_url, './230001015', filename)121 if rejectcodes=='230001016': #é¨çªæªæå®é
ç»å¶122 download_image(request_url, './230001016', filename)123 if rejectcodes=='230001017': #æ ¼å±ç»å¶é误124 download_image(request_url, './230001017', filename)125 if rejectcodes=='230002001': #æ åå¾ä¸æµç»å¾ä¸ç¬¦126 download_image(request_url, './230002001', filename)127 if rejectcodes=='230002002': #é¨æçªç¼ºå¤±128 download_image(request_url, './230002002', filename)129 if rejectcodes=='230003001': #é¨æçªç¼ºå¤±130 download_image(request_url, './230003001', filename)131 if rejectcodes=='230003002': #é¨çªä½ç½®é误132 download_image(request_url, './230003002', filename)133 if rejectcodes=='230003003': #åè½é´å称é误æ缺失134 download_image(request_url, './230003003', filename)135 if rejectcodes=='230003004': #å¢ä½å°ºå¯¸ï¼ä½ç½®é误136 download_image(request_url, './230003004', filename)137 if rejectcodes=='230003005': #æ·åéå138 download_image(request_url, './230003005', filename)139 if rejectcodes=='230003006': #å¤ä½é¨æçª140 download_image(request_url, './230003006', filename)141 if rejectcodes=='230003007': #缺失å¢ä½142 download_image(request_url, './230003007', filename)143 if rejectcodes=='230003008': #æªç»å¶æ¥¼æ¢¯144 download_image(request_url, './230003008', filename)145 if rejectcodes=='230003009': #楼梯ä½ç½®é误146 download_image(request_url, './230003009', filename)147 if rejectcodes=='230003010': #楼å±æ 注缺失æé误148 download_image(request_url, './230003010', filename)149 if rejectcodes=='230003011': #缺失åè½é´150 download_image(request_url, './230003011', filename)151 if rejectcodes=='230003012': #å
¶å®ç±»é®é¢152 download_image(request_url, './230003012', filename)153 if rejectcodes=='230002003': #é¨çªä½ç½®é误154 download_image(request_url, './230002003', filename)155 if rejectcodes=='230002004': #åè½é´å称é误æ缺失156 download_image(request_url, './230002004', filename)157 if rejectcodes=='230002005': #å¢ä½å°ºå¯¸ï¼ä½ç½®é误158 download_image(request_url, './230002005', filename)159 if rejectcodes=='230002006': #æ·åéå160 download_image(request_url, './230002006', filename)161 if rejectcodes=='230002007': #å¤ä½é¨æçª162 download_image(request_url, './230002007', filename)163 if rejectcodes=='230002008': #缺失å¢ä½164 download_image(request_url, './230002008', filename)165 if rejectcodes=='230002009': #æªç»å¶æ¥¼æ¢¯166 download_image(request_url, './230002009', filename)167 if rejectcodes=='230002010': #楼梯ä½ç½®é误168 download_image(request_url, './230002010', filename)169 if rejectcodes=='230002011': #楼å±æ 注缺失æé误170 download_image(request_url, './230002011', filename)171 if rejectcodes=='230002012': #缺失åè½é´172 download_image(request_url, './230002012', filename)173 if rejectcodes == '230002013': #å
¶ä»ç±»é®é¢174 download_image(request_url, './230002013', filename)175 if rejectcodes=='230001018': #éç§ç©ºé´æ 注é误176 download_image(request_url, './230001018', filename)177 if rejectcodes=='230001019': #é¨å¤§å°ä¸ä¸ï¼90度ï¼178 download_image(request_url, './230001019', filename)179 if rejectcodes=='230001020': #åè½é´æ°éä¸ç
§çä¸ç¬¦180 download_image(request_url, './230001020', filename)181 if rejectcodes=='230001021': #å¢ä½ä¸ç¬¦182 download_image(request_url, './230001021', filename)183 if rejectcodes=='230001022': #å
¶å®ç±»é®é¢184 download_image(request_url, './230001022', filename)185 if rejectcodes=='220123': #åç¹å¾ä¸åèå¾å»ºç«å
³ç³»é误186 download_image(request_url, './220123', filename)187 if rejectcodes=='220124': #å¼æ¾å¨æ¿ç»å¶é误188 download_image(request_url, './220124', filename)189 if rejectcodes=='220125': #å±é«ç¼ºå¤±190 download_image(request_url, './220125', filename)191 if rejectcodes=='220126': #æ·åç»æé误192 download_image(request_url, './220126', filename)193 if rejectcodes=='220127': #æ·åæ述缺失194 download_image(request_url, './220127', filename)195 if rejectcodes=='240001': #ç»è´¨é®é¢196 download_image(request_url, './240001', filename)197 if rejectcodes=='240002': #空é´é®é¢198 download_image(request_url, './240002', filename)199 if rejectcodes=='240003': #éç§é®é¢200 download_image(request_url, './240003', filename)201 if rejectcodes == '240004': #æ°éã设置é®é¢202 download_image(request_url, './240004', filename)203 if rejectcodes=='240005': #人ç©é®é¢204 download_image(request_url, './240005', filename)205 if rejectcodes=='240006': #失çé®é¢206 download_image(request_url, './240006', filename)207 if rejectcodes=='240007': #æ°´å°208 download_image(request_url, './240007', filename)209 if rejectcodes=='240008': #çå®æ§210 download_image(request_url, './240008', filename)211 if rejectcodes=='240001001': #模ç³212 download_image(request_url, './240001001', filename)213 if rejectcodes=='240001002': #é»æ214 download_image(request_url, './240001002', filename)215 if rejectcodes=='240001003': #æå
216 download_image(request_url, './240001003', filename)217 if rejectcodes=='240001004': #åªç¹218 download_image(request_url, './240001004', filename)219 if rejectcodes == '240002001': #æ ä¸é¢å¢220 download_image(request_url, './240002001', filename)221 if rejectcodes == '240002002': #å°é¢è¿å¤§222 download_image(request_url, './240002002', filename)223 if rejectcodes == '240002003': #å°é¢è¿å°224 download_image(request_url, './240002003', filename)225 if rejectcodes == '240002004': #åä¸ç©å226 download_image(request_url, './240002004', filename)227 if rejectcodes == '240002005': #ä¸è½éé¨éå¢ææ228 download_image(request_url, './240002005', filename)229 if rejectcodes == '240003001': #éç§è¡£ç©230 download_image(request_url, './240003001', filename)231 if rejectcodes == '240003002': #马桶ç232 download_image(request_url, './240003002', filename)233 if rejectcodes == '240004001': #è§åº¦éå¤234 download_image(request_url, './240004001', filename)235 if rejectcodes == '240004002': #æ°éä¸ç¬¦236 download_image(request_url, './240004002', filename)237 if rejectcodes == '240004003': #ä¼ éä½ç½®238 download_image(request_url, './240004003', filename)239 if rejectcodes == '240004004':240 download_image(request_url, './240004004', filename)241 if rejectcodes == '240005001':242 download_image(request_url, './240005001', filename)243 if rejectcodes == '240005002':244 download_image(request_url, './240005002', filename)245 if rejectcodes == '240005003':246 download_image(request_url, './240005003', filename)247 if rejectcodes == '240005004':248 download_image(request_url, './240005004', filename)249 if rejectcodes == '240006001':250 download_image(request_url, './240006001', filename)251 if rejectcodes == '240006002':252 download_image(request_url, './240006002', filename)253 if rejectcodes == '240007001':254 download_image(request_url, './240007001', filename)255 if rejectcodes == '240007002':256 download_image(request_url, './240007002', filename)257 if rejectcodes == '240008001':258 download_image(request_url, './240008001', filename)259 if rejectcodes == '240008002':260 download_image(request_url, './240008002', filename)261 if rejectcodes == '240009001':262 download_image(request_url, './240009001', filename)263 if rejectcodes == '240010001':264 download_image(request_url, './240010001', filename)265 if rejectcodes == '440001001':266 download_image(request_url, './440001001', filename)267 if rejectcodes == '440001009':268 download_image(request_url, './440001009', filename)269 if rejectcodes == '440001011':270 download_image(request_url, './440001011', filename)271 if rejectcodes == '440001013':272 download_image(request_url, './440001013', filename)273if __name__ == "__main__":...
routes.py
Source:routes.py
...87 app.config["UPLOADED_IMAGES"], file_name), file_name)88 return redirect(url_for('download_image', filename=file_name))89 return render_template("index.html")90@app.route("/uploads/<filename>")91def download_image(filename):...
lpl-thumbnails-downloader.py
Source:lpl-thumbnails-downloader.py
...28 console = os.path.splitext(os.path.basename(console))[0]29 if 'MAME' in console:30 return 'MAME'31 return console32def download_image(folder, console, game, retry, realname=""):33 repo = "https://raw.githubusercontent.com/libretro-thumbnails/" + urllib.parse.quote(console.replace(' ','_')) + "/master/"34 clean_game = game35 if realname == '':36 realname = game37 original_game = realname.replace('/', '_').replace(':', '_') + '.png'38 game = urllib.parse.quote(game.replace('&', '_').replace(':', '_').replace('/', '_') + '.png')39 thumbnail = 040 if not os.path.exists(folder + '/Named_Boxarts/' + original_game):41 try:42 urllib.request.urlretrieve(repo + 'Named_Boxarts/' + game, folder + '/Named_Boxarts/' + original_game)43 thumbnail += 144 except:45 pass46 else:47 thumbnail += 148 if not os.path.exists(folder + '/Named_Snaps/' + original_game):49 try:50 urllib.request.urlretrieve(repo + 'Named_Snaps/' + game, folder + '/Named_Snaps/' + original_game)51 thumbnail += 152 except:53 pass54 else:55 thumbnail += 156 if not os.path.exists(folder + '/Named_Titles/' + original_game):57 try:58 urllib.request.urlretrieve(repo + 'Named_Titles/' + game, folder + '/Named_Titles/' + original_game)59 thumbnail += 160 except:61 pass62 else:63 thumbnail += 164 if thumbnail == 0:65 print("Not found " + clean_game + ' at ' + repo + 'Named_Boxarts/' + game)66 if retry is False:67 try:68 if clean_game.count(',') > 1:69 # Try with switching stuff inside parenthesis because the game can have different filenames70 s = re.findall('\((.*?)\)', clean_game)71 s = s[0].split(', ')72 try_game_name = s[1] + ', ' + s[0].replace(', ', '')73 clean_game = clean_game.replace(s[0] + ', ' + s[1], try_game_name)74 download_image(folder, console, clean_game, True, realname)75 download_image(folder, console, clean_game.replace(',', ''), True, realname)76 except:77 pass78 if '(Euro)' in clean_game:79 # Try with bootleg80 clean_game = clean_game.replace('(Euro)', '(bootleg)')81 download_image(folder, console, clean_game, True, realname)82 if '(' not in clean_game:83 # Try with adding a country84 download_image(folder, console, clean_game + " (Japan)", True, realname)85 download_image(folder, console, clean_game + " (USA)", True, realname)86 download_image(folder, console, clean_game + " (Europe)", True, realname)87 if '(Europe)' in clean_game:88 # Try with replacing a country89 clean_game = clean_game.replace('(Europe)', '(USA)')90 download_image(folder, console, clean_game, True, realname)91 else:92 print(' Downloaded ' + realname + ' ' + str(thumbnail) + ' thumbnails')93console = get_console_name(args.playlist)94folder = create_folders(console)95print('Downloading ' + console + ' thumbnails')96with open(args.playlist, "r") as read_file:97 data = json.load(read_file)98 if len(data['items']) > 0:99 for item in data['items']:100 download_image(folder, console, item['label'], False)101 else:102 print('Empty playlist.')...
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!!