Best Python code snippet using locust
gl-isf.py
Source:gl-isf.py
1from selenium import webdriver2from selenium.webdriver.common.keys import Keys3from selenium.webdriver.common.by import By4from selenium.webdriver.support.ui import WebDriverWait5from selenium.webdriver.support import expected_conditions as EC6from bs4 import BeautifulSoup7import urllib.request8import requests9import datetime10date_time_now = datetime.datetime.now()11import time12import os13import os.path14from colorama import init # module imported for color support15init()16from colorama import Fore,Back,Style17import argparse18class app_info:19 shortname = "GL-isf"20 name = "GameList-import.scrape.format"21 description = "imports, scrapes and formats your game list!"22 version = "0.23a"23 by = "darkk!"24parser = argparse.ArgumentParser(prog=app_info.shortname, description=app_info.description) # argparse parser config25parser.add_argument("-v", "--version", action="version", version="[GL-isf] GameList-import.scrape.format v" + app_info.version + " by " + app_info.by)26# print(f"[{app_info.shortname}] {app_info.name} v{app_info.version} by {app_info.by}") #* like previous line, but using (f")27parser.add_argument("input_file", help="filename of gamelist to read")28parser.add_argument("output_file", nargs="?", help="filename of formatted list to write (default: [.\gamelist.glf])", default=".\gamelist.glf")29# parser.add_argument("pricetable", nargs="?", help="filename of pricetable to read", default="none")30parser.add_argument("-f", "--format", help="formatting of output_file [reddit] (default: [reddit])", default="reddit")31parser.add_argument("-if", "--input_format", nargs="?", help="formatting of input_file [text-store] (default: [text-store])", default="text-store")32parser.add_argument("-ar", "--autorecheck", help="enables automatic re-checking of failed scrapes", action="store_true")33args = parser.parse_args()34app_ascii = """35 ________.____ .__ _____ 36 / _____/| | |__| ______/ ____\ 37 / \ ___| | ______ | |/ ___\ __\ 38 \ \_\ | |___ /_____/ | |\___ \ | | 39 \______ |_______ \ |__/____ >|__| 40 \/ \/ \/ 41 """42app_ascii_alt = """43 ________.____ .__ _____ 44 / _____/| | |__| ______/ ____\ 45 ______ ______ ______ / \ ___| | ______ | |/ ___\ __\ ______ ______ ______ 46 /_____/ /_____/ /_____/ \ \_\ | |___ /_____/ | |\___ \ | | /_____/ /_____/ /_____/ 47 \______ |_______ \ |__/____ >|__| 48 \/ \/ \/ """49print(f"{Fore.CYAN}{app_ascii_alt}{Style.RESET_ALL}") # initialization50print(f"\n[{Fore.CYAN}GL-isf/init{Style.RESET_ALL}] Initializing ... ", flush=True, end="")51if os.path.isfile(args.input_file): # checks if input_file and output_file exists plus overwrite prompts for output_file52 pass53else:54 print(f"[{Fore.RED}FAIL!{Style.RESET_ALL}]")55 print(f"[{Fore.CYAN}GL-isf/file_check{Style.RESET_ALL}] input_file {Style.BRIGHT}{args.input_file}{Style.RESET_ALL} {Fore.RED}does not exists!{Style.RESET_ALL}. Cannot continue further. {Style.BRIGHT}EXITING! ...{Style.RESET_ALL}")56 exit()57if os.path.isfile(args.output_file):58 print(f"[{Fore.YELLOW}WARNING!{Style.RESET_ALL}]")59 print(f"[{Fore.CYAN}GL-isf/file_check{Style.RESET_ALL}] output_file {Style.BRIGHT}{args.output_file}{Style.RESET_ALL} {Fore.RED}already exists!{Style.RESET_ALL}")60 overwrite_answer = input(f"[{Fore.CYAN}GL-isf/query{Style.RESET_ALL}] Would you like to overwrite [{Style.BRIGHT}Y{Style.RESET_ALL}/N]? ")61 if overwrite_answer == "Y" or overwrite_answer == "":62 print(f"[{Fore.CYAN}GL-isf/del_file{Style.RESET_ALL}] {Fore.RED}deleting{Style.RESET_ALL} output_file {Style.BRIGHT}{args.output_file}{Style.RESET_ALL} ... ", flush=True, end="")63 os.remove(args.output_file)64 print(f"[{Fore.GREEN}OK!{Style.RESET_ALL}]")65 elif overwrite_answer == "N":66 print(f"[{Fore.CYAN}GL-isf/quit{Style.RESET_ALL}] Cannot continue further. {Style.BRIGHT}EXITING! ...{Style.RESET_ALL}")67 exit()68 else:69 print(f"[{Fore.CYAN}GL-isf/query_check{Style.RESET_ALL}] {Fore.RED}Invalid answer!{Style.RESET_ALL} {Style.BRIGHT}EXITING! ...{Style.RESET_ALL}")70 exit()71else:72 print(f"[{Fore.GREEN}OK!{Style.RESET_ALL}]")73print(f"[{Fore.CYAN}GL-isf/init_cmpt{Style.RESET_ALL}] Initialization completed! Welcome to {Style.BRIGHT}[{app_info.shortname}]{app_info.name}{Style.RESET_ALL} v{Style.BRIGHT}{app_info.version}{Style.RESET_ALL} by {Style.BRIGHT}{app_info.by}{Style.RESET_ALL}\n")74ticbig = time.time()75filereader = open(args.input_file, "r") # calculates number of games(lines) in input_file76num_games = 077for line in filereader:78 num_games += 179filereader.close()80def time_convert(seconds): # function that converts seconds to "XXh XXm XXs" format81 seconds = seconds % (24 * 3600)82 hour = seconds // 360083 seconds %= 360084 minutes = seconds // 6085 seconds %= 6086 if int(hour) == 0 and int(minutes) == 0 and int(seconds) == 0: # prints only applicable formats plus infinity87 return("~")88 elif int(hour) == 0 and int(minutes) == 0:89 return(f"{int(seconds)}s")90 elif int(hour) == 0:91 return(f"{int(minutes)}m {int(seconds)}s")92 else:93 return(f"{int(hour)}h {int(minutes)}m {int(seconds)}s")94def progress_bar(num_processing, num_games, eta, warning_counter, error_counter): # function that displays progress_bar and stat_line95 percentage = num_processing / num_games * 10096 percentage_str = round(percentage, 1)97 stat_counter = f" [{Fore.GREEN}{num_processing}{Style.RESET_ALL}/{Style.BRIGHT}{Fore.CYAN}{num_games}{Style.RESET_ALL} {Style.BRIGHT}{percentage_str}%{Style.RESET_ALL} - {Style.BRIGHT}{eta}{Style.RESET_ALL} left ({Fore.YELLOW}#{warning_counter}{Style.RESET_ALL},{Fore.RED}!{error_counter}{Style.RESET_ALL})] "98 if percentage >= 0 and percentage < 5:99 return(f"[{Fore.GREEN}. {Style.RESET_ALL}]{stat_counter}")100 elif percentage >= 5 and percentage < 10:101 return(f"[{Fore.GREEN}: {Style.RESET_ALL}]{stat_counter}")102 elif percentage >= 10 and percentage < 15:103 return(f"[{Fore.GREEN}:. {Style.RESET_ALL}]{stat_counter}")104 elif percentage >= 15 and percentage < 20:105 return(f"[{Fore.GREEN}:: {Style.RESET_ALL}]{stat_counter}")106 elif percentage >= 20 and percentage < 25:107 return(f"[{Fore.GREEN}::. {Style.RESET_ALL}]{stat_counter}")108 elif percentage >= 25 and percentage < 30:109 return(f"[{Fore.GREEN}::: {Style.RESET_ALL}]{stat_counter}")110 elif percentage >= 30 and percentage < 35:111 return(f"[{Fore.GREEN}:::{Fore.YELLOW}. {Style.RESET_ALL}]{stat_counter}")112 elif percentage >= 35 and percentage < 40:113 return(f"[{Fore.GREEN}:::{Fore.YELLOW}: {Style.RESET_ALL}]{stat_counter}")114 elif percentage >= 40 and percentage < 45:115 return(f"[{Fore.GREEN}:::{Fore.YELLOW}:. {Style.RESET_ALL}]{stat_counter}")116 elif percentage >= 45 and percentage < 50:117 return(f"[{Fore.GREEN}:::{Fore.YELLOW}:: {Style.RESET_ALL}]{stat_counter}")118 elif percentage >= 50 and percentage < 55:119 return(f"[{Fore.GREEN}:::{Fore.YELLOW}::. {Style.RESET_ALL}]{stat_counter}")120 elif percentage >= 55 and percentage < 60:121 return(f"[{Fore.GREEN}:::{Fore.YELLOW}::: {Style.RESET_ALL}]{stat_counter}")122 elif percentage >= 60 and percentage < 65:123 return(f"[{Fore.GREEN}:::{Fore.YELLOW}:::. {Style.RESET_ALL}]{stat_counter}")124 elif percentage >= 65 and percentage < 70:125 return(f"[{Fore.GREEN}:::{Fore.YELLOW}:::: {Style.RESET_ALL}]{stat_counter}")126 elif percentage >= 70 and percentage < 75:127 return(f"[{Fore.GREEN}:::{Fore.YELLOW}::::{Fore.RED}. {Style.RESET_ALL}]{stat_counter}")128 elif percentage >= 75 and percentage < 80:129 return(f"[{Fore.GREEN}:::{Fore.YELLOW}::::{Fore.RED}: {Style.RESET_ALL}]{stat_counter}")130 elif percentage >= 80 and percentage < 85:131 return(f"[{Fore.GREEN}:::{Fore.YELLOW}::::{Fore.RED}:. {Style.RESET_ALL}]{stat_counter}")132 elif percentage >= 85 and percentage < 90:133 return(f"[{Fore.GREEN}:::{Fore.YELLOW}::::{Fore.RED}:: {Style.RESET_ALL}]{stat_counter}")134 elif percentage >= 90 and percentage < 95:135 return(f"[{Fore.GREEN}:::{Fore.YELLOW}::::{Fore.RED}::.{Style.RESET_ALL}]{stat_counter}")136 elif percentage >= 95 and percentage <= 100:137 return(f"[{Fore.GREEN}:::{Fore.YELLOW}::::{Fore.RED}:::{Style.RESET_ALL}]{stat_counter}")138def ui_tester(): # ui_tester function used for dev/debuggings purposes139 num_processing = 0140 last_tt = 0141 time_sum = 0142 game_title = "Doom 8"143 game_price = 59.99144 num_games = 29145 print(f"[{Fore.CYAN}GL-isf/init{Style.RESET_ALL}] Initializing {Style.BRIGHT}{app_info.name}{Style.RESET_ALL} v{Style.BRIGHT}{app_info.version}{Style.RESET_ALL} by {Style.BRIGHT}{app_info.by}{Style.RESET_ALL}\n")146 for counter in range(num_games):147 num_processing += 1148 tic = time.time()149 time_sum += last_tt150 if last_tt == 0:151 eta = "~"152 eta_avg = "~"153 else:154 eta = round((num_games - num_processing * last_tt) / 60, 2)155 eta_avg = round((num_games - num_processing) * (time_sum / (num_processing - 1)), 2)156 eta_avg = time_convert(eta_avg)157 print(f"{progress_bar(num_processing, num_games, eta_avg, warning_counter, error_counter)}[{Fore.CYAN}GL-isf/import{Style.RESET_ALL}] {Style.BRIGHT}Importing{Style.RESET_ALL} game info ... ", flush=True, end="")158 print(f"[{Fore.GREEN}OK!{Style.RESET_ALL}]")159 print(f"{progress_bar(num_processing, num_games, eta_avg, warning_counter, error_counter)}[{Fore.CYAN}GL-isf/scrape{Style.RESET_ALL}] {Style.BRIGHT}Scraping{Style.RESET_ALL} AKS.url of {Fore.BLUE}{game_title}{Style.RESET_ALL} ... ", flush=True, end="")160 print(f"[{Fore.GREEN}OK!{Style.RESET_ALL}]")161 time.sleep(3)162 print(f"{progress_bar(num_processing, num_games, eta_avg, warning_counter, error_counter)}[{Fore.CYAN}GL-isf/scrape{Style.RESET_ALL}] {Style.BRIGHT}Scraping{Style.RESET_ALL} AKS.lowest.price of {Fore.BLUE}{game_title}{Style.RESET_ALL} ... ", flush=True, end="")163 print(f"[{Fore.GREEN}OK!{Style.RESET_ALL}]")164 toc = time.time()165 tictoc = round(toc - tic, 2)166 last_tt = tictoc167 print(f"{progress_bar(num_processing, num_games, eta_avg, warning_counter, error_counter)}[{Fore.CYAN}GL-isf/proc-m{Style.RESET_ALL}] Processed {Fore.BLUE}{game_title}{Style.RESET_ALL} / {Fore.YELLOW}{game_price}e{Style.RESET_ALL} in {Style.BRIGHT}{tictoc}s{Style.RESET_ALL}")168 return()169# ui_tester() #* enable to use ui_tester170# exit()171intput_file_str = args.input_file.ljust(18) # print options/settings172output_file_str = args.output_file.ljust(18)173format_str = args.format.ljust(11)174pricetable_str = "none".ljust(18)175num_games_str = str(num_games).ljust(5)176if args.autorecheck == True:177 ar_option_str = f"on"178else:179 ar_option_str = f"off"180ar_option_str = ar_option_str.ljust(13)181print(f"{Fore.CYAN}.: [{Style.RESET_ALL} {Fore.GREEN}input_file{Style.RESET_ALL} {Fore.CYAN}] . [{Style.RESET_ALL} {Fore.YELLOW}output_file{Style.RESET_ALL} {Fore.CYAN}] . [{Style.RESET_ALL} {Fore.BLUE}pricetable_file {Style.RESET_ALL}{Fore.CYAN}] . [{Style.RESET_ALL} {Fore.MAGENTA}format{Style.RESET_ALL} {Fore.CYAN}] . [{Style.RESET_ALL} {Style.BRIGHT}{Fore.RED}games{Style.RESET_ALL} {Fore.CYAN}] . [{Style.RESET_ALL} {Style.BRIGHT}auto_recheck {Style.RESET_ALL} {Fore.CYAN}] :.{Style.RESET_ALL}{Style.RESET_ALL}")182print(f"{Fore.CYAN}.: [{Style.RESET_ALL} {Style.BRIGHT}{intput_file_str}{Style.RESET_ALL} {Fore.CYAN}] . [{Style.RESET_ALL} {Style.BRIGHT}{output_file_str}{Style.RESET_ALL} {Fore.CYAN}] . [{Style.RESET_ALL} {Style.BRIGHT}{pricetable_str} {Style.RESET_ALL}{Fore.CYAN}] . [{Style.RESET_ALL} {Style.BRIGHT}{format_str}{Style.RESET_ALL} {Fore.CYAN}] . [{Style.RESET_ALL} {Style.BRIGHT}{num_games_str}{Style.RESET_ALL} {Fore.CYAN}] . [{Style.RESET_ALL}{Style.BRIGHT} {ar_option_str}{Style.RESET_ALL} {Fore.CYAN}] :.{Style.RESET_ALL}\n")183def main_scraper(): # main_scraper function (import data, scrape url, scrape price and format/export data)184 num_processing = 0185 last_tt = 0186 time_sum = 0187 error_counter = 0188 warning_counter = 0189 success_counter = 0190 ar_counter = 0191 glf_reader = open(args.input_file, "r")192 for line in glf_reader: # reading data from input_file line by line193 tic = time.time()194 num_processing += 1195 time_sum += last_tt196 ar_run = False197 ar_ran = False198 if last_tt == 0: # eta calculations199 eta = "~"200 eta_avg = "~"201 else:202 eta = round(((num_games - num_processing) * last_tt) / 60, 2)203 eta_avg = round((num_games - num_processing) * (time_sum / (num_processing - 1)), 2)204 eta_avg = time_convert(eta_avg)205 print(f"{progress_bar(num_processing, num_games, eta_avg, warning_counter, error_counter)}[{Fore.CYAN}GL-isf/import{Style.RESET_ALL}] {Style.BRIGHT}Importing{Style.RESET_ALL} game info ... ", flush=True, end="")206 stripped_line = line.strip()207 game_title = ""208 steam_url = ""209 division = False210 countdown = 4211 if args.input_format == "text-store": # checks what input_format to use212 for idx in range(len(stripped_line)): # game title and steam_url importing from stripped_line via text-store format213 char = stripped_line[idx]214 try:215 if stripped_line[idx + 1] == " " and stripped_line[idx + 2] == "-" and stripped_line[idx + 4] == " ":216 division = True217 except:218 pass219 if division == True:220 countdown -= 1221 if division == True and countdown < 0:222 steam_url += char223 elif countdown >= 3:224 game_title += char225 print(f"[{Fore.GREEN}OK!{Style.RESET_ALL}]")226 else:227 print(f"[{Fore.RED}FAIL!{Style.RESET_ALL}]")228 exit()229 ar_text = f"{game_title} -- {steam_url}"230 print(f"{progress_bar(num_processing, num_games, eta_avg, warning_counter, error_counter)}[{Fore.CYAN}GL-isf/scrape{Style.RESET_ALL}] {Style.BRIGHT}Scraping{Style.RESET_ALL} AKS.url of {Fore.BLUE}{game_title}{Style.RESET_ALL} ... ", flush=True, end="")231 driver = webdriver.Firefox() # scraping correct scrape_url for game via selenium232 driver.get("https://www.allkeyshop.com/blog/catalogue/")233 elem = driver.find_element_by_id('search-form-keywords')234 elem.clear()235 elem.send_keys(game_title)236 # time.sleep(2)237 element = WebDriverWait(driver, 5).until(EC.presence_of_element_located((By.CLASS_NAME, "search-results-row-link"))) # 5 second inclusive wait238 first_match = driver.find_element_by_class_name('search-results-row-link') # best match for game_title239 first_match.send_keys(Keys.RETURN)240 time.sleep(0.5) # additional sleep for enhanced success. #? is it possible to do this via selenium waits?241 aks_url = driver.current_url # game_title aks-url used for price_scraping242 assert "No results found." not in driver.page_source #? is this needed?243 driver.close()244 if "catalogue" in aks_url: # scraping failed & activating autorecheck if needed/enabled245 print(f"[{Fore.RED}FAIL!{Style.RESET_ALL}]")246 error_counter += 1247 if args.autorecheck == True:248 ar_run = True249 else:250 pass251 # if autorecheck == "True": #! deprecated, not using this method anymore!252 # os.remove(".\autorecheck")253 # ar_filewriter = open(".\autorecheck", "a")254 # ar_filewriter.write(str(ar_text) + "\n")255 # ar_filewriter.close()256 # else:257 # pass258 else:259 print(f"[{Fore.GREEN}OK!{Style.RESET_ALL}]")260 if ar_run == True: # doing the auto_recheck re-scrape if enabled/needed (more patient processing too) [copy/pasted code from before] #? convert these to function?261 ar_counter += 1262 print(f"{progress_bar(num_processing, num_games, eta_avg, warning_counter, error_counter)}[{Fore.CYAN}GL-isf/ar_scrape{Style.RESET_ALL}] [{Style.BRIGHT}{Fore.GREEN}AUTO_RECHECK!{Style.RESET_ALL}] {Style.BRIGHT}Re-Scraping{Style.RESET_ALL} AKS.url of {Fore.BLUE}{game_title}{Style.RESET_ALL} ... ", flush=True, end="")263 driver = webdriver.Firefox()264 driver.get("https://www.allkeyshop.com/blog/catalogue/")265 elem = driver.find_element_by_id('search-form-keywords')266 elem.clear()267 elem.send_keys(game_title)268 time.sleep(0.5)269 element = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.CLASS_NAME, "search-results-row-link")))270 first_match = driver.find_element_by_class_name('search-results-row-link')271 first_match.send_keys(Keys.RETURN)272 time.sleep(1)273 aks_url = driver.current_url274 assert "No results found." not in driver.page_source275 driver.close()276 if "catalogue" in aks_url:277 print(f"[{Fore.RED}FAIL!{Style.RESET_ALL}]")278 else:279 error_counter -= 1280 print(f"[{Fore.GREEN}OK!{Style.RESET_ALL}]")281 ar_run = False282 ar_ran = True283 else:284 pass285 print(f"{progress_bar(num_processing, num_games, eta_avg, warning_counter, error_counter)}[{Fore.CYAN}GL-isf/scrape{Style.RESET_ALL}] {Style.BRIGHT}Scraping{Style.RESET_ALL} AKS.lowest.price of {Fore.BLUE}{game_title}{Style.RESET_ALL} ... ", flush=True, end="")286 aks_proc = urllib.request.urlopen(aks_url).read() # scraping price for game via bs4287 soup = BeautifulSoup(aks_proc, "lxml")288 pricefinder = soup.find(itemprop="lowPrice") # lowest price for game (raw_format)289 ff = False290 sf = False291 game_price = ""292 for char in str(pricefinder): # converting game price to usable formatting (xxx.xx)293 if char == '"' and ff == False:294 ff = True295 elif char == '"' and ff == True:296 sf = True297 elif ff == True and sf == False:298 game_price += char299 else:300 pass301 if not game_price and "catalogue" in aks_url: # printing failed/not_found prices and adding MCN! tag to output_file #* if modifying this code, also check copypasted AR ones below!302 print(f"[{Fore.RED}FAIL!{Style.RESET_ALL}]")303 game_price_str = f"{Fore.RED}N/A{Style.RESET_ALL}"304 game_price_format = "MCN!"305 if args.autorecheck == True:306 ar_run = True307 else:308 pass309 elif not game_price:310 print(f"[{Fore.YELLOW}NOT_FOUND!{Style.RESET_ALL}]")311 game_price_str = f"{Fore.RED}N/A{Style.RESET_ALL}"312 game_price_format = "MCN!"313 warning_counter += 1314 if args.autorecheck == True:315 ar_run = True316 else:317 pass318 # if autorecheck == "True": #! deprecated, not using this method anymore!319 # os.remove(".\autorecheck")320 # ar_filewriter = open(".\autorecheck", "a")321 # ar_filewriter.write(str(ar_text) + "\n")322 # ar_filewriter.close()323 # else:324 # pass325 else:326 print(f"[{Fore.GREEN}OK!{Style.RESET_ALL}]")327 game_price_str = f"{Fore.GREEN}{game_price}e{Style.RESET_ALL}"328 game_price_format = game_price329 success_counter += 1330 if ar_run == True: # doing the auto_recheck re-scrape if enabled/needed (more patient processing too) [copy/pasted code from before] #? convert these to function?331 ar_counter += 1332 print(f"{progress_bar(num_processing, num_games, eta_avg, warning_counter, error_counter)}[{Fore.CYAN}GL-isf/ar_scrape{Style.RESET_ALL}] [{Style.BRIGHT}{Fore.GREEN}AUTO_RECHECK!{Style.RESET_ALL}] {Style.BRIGHT}Re-Scraping{Style.RESET_ALL} AKS.lowest.price of {Fore.BLUE}{game_title}{Style.RESET_ALL} ... ", flush=True, end="")333 aks_proc = urllib.request.urlopen(aks_url).read()334 time.sleep(0.1)335 soup = BeautifulSoup(aks_proc, "lxml")336 time.sleep(0.1)337 pricefinder = soup.find(itemprop="lowPrice")338 ff = False339 sf = False340 game_price = ""341 for char in str(pricefinder): # converting game price to usable formatting (AR)342 if char == '"' and ff == False:343 ff = True344 elif char == '"' and ff == True:345 sf = True346 elif ff == True and sf == False:347 game_price += char348 else:349 pass350 if not game_price and "catalogue" in aks_url: # printing failed/not_found prices and adding MCN! tag to output_file (AR)351 print(f"[{Fore.RED}FAIL!{Style.RESET_ALL}]")352 game_price_str = f"{Fore.RED}N/A{Style.RESET_ALL}"353 game_price_format = "MCN!"354 elif not game_price:355 print(f"[{Fore.YELLOW}NOT_FOUND!{Style.RESET_ALL}]")356 game_price_str = f"{Fore.RED}N/A{Style.RESET_ALL}"357 game_price_format = "MCN!"358 else:359 print(f"[{Fore.GREEN}OK!{Style.RESET_ALL}]")360 game_price_str = f"{Fore.GREEN}{game_price}e{Style.RESET_ALL}"361 game_price_format = game_price362 success_counter += 1363 warning_counter -= 1364 ar_ran = True365 else:366 pass367 toc = time.time()368 tictoc = round(toc - tic, 2)369 tac = round(toc - ticbig, 2)370 last_tt = tictoc371 filewriter = open(args.output_file, "a") # output_file formatting / writing372 if args.format == "reddit":373 formatted_text = f"* [{game_title}]({steam_url}) - **_{game_price_format}e**_ "374 filewriter.write(str(formatted_text) + "\n")375 elif args.format == "phpbb":376 pass377 filewriter.close()378 if ar_ran == True: # printing completed processing this item msg379 ar_symbol = f" ({Style.BRIGHT}{Fore.GREEN}AR{Style.RESET_ALL})"380 else:381 ar_symbol = ""382 print(f" {Style.BRIGHT}-->{Style.RESET_ALL} [{Fore.CYAN}GL-isf/sgp-cmsg{Style.RESET_ALL}] Processed{ar_symbol} {Fore.BLUE}{game_title}{Style.RESET_ALL} / {game_price_str} in {Style.BRIGHT}{tictoc}s{Style.RESET_ALL}. {Style.BRIGHT}{time_convert(tac)}{Style.RESET_ALL} elapsed and {Style.BRIGHT}{eta_avg}{Style.RESET_ALL} left.")383 glf_reader.close()384 return(success_counter, error_counter, warning_counter, ar_counter, num_games)385success_counter, error_counter, warning_counter, ar_counter, num_games = main_scraper()386# if autorecheck == "True": #! deprecated, not using this method anymore!387# ar_filereader = open(".\autorecheck", "r")388# for line in ar_filereader:389# tic = time.time()390# num_processing += 1391# time_sum += last_tt392# ar_filewriter.close()393# os.remove(".\autorecheck")394# else:395# pass396tocbig = time.time() # printing final messages397tictocbig = round(tocbig - ticbig, 2)398success_percentage = (success_counter + warning_counter) / num_games * 100 # success percentage calculations and colorization399if success_percentage >= 90:400 success_percentage_op = f"{Fore.GREEN}{success_percentage}%{Style.RESET_ALL}"401elif success_percentage >= 70:402 success_percentage_op = f"{Fore.YELLOW}{success_percentage}%{Style.RESET_ALL}"403else:404 success_percentage_op = f"{Fore.RED}{success_percentage}%{Style.RESET_ALL}"405if success_percentage != 100:406 mcn_text = f'\n[{Fore.CYAN}GL-isf/mcn_txt{Style.RESET_ALL}] Please find "{Style.BRIGHT}MCN!{Style.RESET_ALL}" in {Style.BRIGHT}{args.output_file}{Style.RESET_ALL} for prices needed for manual check! (or do an re-run for those items / enable auto-recheck!)'407else:408 mcn_text = ""409print(f"\n[{Fore.CYAN}GL-isf/fin{Style.RESET_ALL}] Operation {Style.BRIGHT}completed{Style.RESET_ALL} in {Style.BRIGHT}{time_convert(tictocbig)}{Style.RESET_ALL}! Success ratio is {success_percentage_op} - {Fore.GREEN}{success_counter}{Style.RESET_ALL} succesful, {Fore.YELLOW}{warning_counter}{Style.RESET_ALL} warnings and {Fore.RED}{error_counter}{Style.RESET_ALL} errors. Auto-Recheck ran {Style.BRIGHT}{ar_counter}{Style.RESET_ALL} times. Your data is saved in {Style.BRIGHT}{args.output_file}{Style.RESET_ALL}. {mcn_text}\n")410print(f" {Fore.CYAN}-{Style.RESET_ALL} Thanks for using {Style.BRIGHT}{app_info.name}{Style.RESET_ALL} v{Style.BRIGHT}{app_info.version}{Style.RESET_ALL} by {Style.BRIGHT}{app_info.by}{Style.RESET_ALL}")411print(f"{Fore.CYAN}{app_ascii}{Style.RESET_ALL}")412# exstr = "Supraland -- https://store.steampowered.com/app/813630/" #* early code for reference413# g_title = ""414# s_url = ""415# division = False416# c_down = 4417# for idx in range(len(exstr)):418# char = exstr[idx]419# try:420# if exstr[idx + 1] == " " and exstr[idx + 2] == "-" and exstr[idx + 4] == " ":421# division = True422# except:423# pass424# if division == True:425# c_down -= 1426# if division == True and c_down < 0:427# s_url += char428# elif c_down >= 3:429# g_title += char430# print(f"title: {g_title} - url: {s_url}")431# glf_reader = open("testlist.glf", "r")432# for line in glf_reader:433# stripped_line = line.strip()434# game_title = ""435# steam_url = ""436# division = False437# countdown = 4438# for idx in range(len(stripped_line)):439# char = stripped_line[idx]440# try:441# if stripped_line[idx + 1] == " " and stripped_line[idx + 2] == "-" and stripped_line[idx + 4] == " ":442# division = True443# except:444# pass445# if division == True:446# countdown -= 1447# if division == True and countdown < 0:448# steam_url += char449# elif countdown >= 3:450# game_title += char451# print(f"title: {game_title} url: {steam_url}")...
InstagramPyCLI.py
Source:InstagramPyCLI.py
1import datetime2import sys3from InstagramPy import AppInfo4from .colors import *5class InstagramPyCLI():6 username = None7 started = None8 verbose = 09 pService = None10 def __init__(self, appinfo, started, verbose_level, username, PortableService=None):11 self.pService = PortableService12 try:13 self.verbose = int(verbose_level)14 self.started = started15 self.username = username16 if not appinfo == None:17 appinfo = appinfo18 except:19 self.verbose = 020 self.started = started21 appinfo = AppInfo.appInfo22 if username == None or username == '':23 self.ReportError("username not provided!")24 else:25 self.username = username26 self.HEADER = "{} {} , {}.\n\033[1;32mLet's hit and try the password! {} {} , {}.\n".format(appinfo['name'],27 appinfo['version'],28 appinfo['description'],29 appinfo['year'],30 appinfo['company'],31 appinfo['author'])32 self.HEADER = Fore.MAGENTA + self.HEADER + Style.RESET_ALL33 def ReportError(self, error):34 if self.pService is not None:35 if self.pService.isSetInstagramPyPortable():36 self.pService.terminate()37 print('{}{}\033[1;32m[\033[1;31m!\033[1;32m]\033[1;34mError::{} {}'.format(38 Style.BRIGHT, Fore.RED, Style.RESET_ALL, error))39 sys.exit(-1)40 def PrintHeader(self):41 print(self.HEADER)42 return True43 def PrintDatetime(self):44 print('{}[{}+{}{}]{} {}\033[1;33mStarted{} @ {}\033[0m'.format(Style.BRIGHT,45 Fore.YELLOW,46 Style.RESET_ALL,47 Style.BRIGHT,48 Style.RESET_ALL,49 Fore.MAGENTA,50 Style.RESET_ALL + Fore.YELLOW,51 str(self.started) +52 Style.RESET_ALL53 ))54 return True55 def PrintChangingIP(self):56 print('\033[1;31m[{}*{}\033[1;31m] {}\033[1;35mChanging IP Address... {}\033[0m'.format(Fore.YELLOW,57 Style.RESET_ALL, Fore.GREEN, Style.RESET_ALL))58 return True59 def PrintIPAddress(self, ip):60 print('\033[1;34m[{}\033[1;32m+{}\033[1;34m] {}\033[1;37mCurrent IP{} :: {}{}{}\033[0m'.format(Fore.RED,61 Style.RESET_ALL,62 Fore.YELLOW,63 Style.RESET_ALL,64 Style.BRIGHT,65 str(ip),66 Style.RESET_ALL67 ))68 return True69 def PrintPassword(self, password):70 print('\033[1;32m[{}\033[1;35m+{}\033[1;32m] {}\033[1;32mTrying [FOR] @{} {} :: {}{}{}\033[0m'.format(Fore.GREEN,71 Style.RESET_ALL,72 Fore.CYAN,73 self.username,74 Style.RESET_ALL,75 Style.BRIGHT,76 password,77 Style.RESET_ALL78 ))79 return True80 def PrintRequest(self, req):81 print('\n\033[1;32m[{}\033[1;31m-{}\033[1;32m] --:: {}REQUEST START -> @{} {} ::--\033[0m'.format(Fore.MAGENTA,82 Style.RESET_ALL, Back.CYAN + Style.BRIGHT, self.username, Style.RESET_ALL))83 print('{}{}{} {}{}{}'.format(Fore.GREEN, req.method,84 Style.RESET_ALL, Style.BRIGHT, req.url, Style.RESET_ALL))85 print('{}{}{}'.format(Fore.YELLOW, '\n'.join('{}: {}'.format(k, v)86 for k, v in req.headers.items()), Style.RESET_ALL))87 print('{}{}{}'.format(Style.BRIGHT, req.body, Style.RESET_ALL))88 print('\033[1;32m[{}\033[1;31m+{}\033[1;32m] --:: {}REQUEST END{} ::--\033[0m'.format(Fore.GREEN,89 Style.RESET_ALL, Back.GREEN + Style.BRIGHT, Style.RESET_ALL))90 return True91 def PrintResponse(self, resp):92 print('\033[1;36m\n[{}\033[1;33m!-!{}\033[1;36m] --:: {}\033[1;36mRESPONSE START -> @{} {} \033[1;31m::--\033[0m'.format(Fore.MAGENTA,93 Style.RESET_ALL, Back.CYAN + Style.BRIGHT, self.username, Style.RESET_ALL))94 print('{}{}{}'.format(Style.BRIGHT, str(resp), Style.RESET_ALL))95 print('\033[1;34m[{}\033[1;32m+{}\033[1;34m]\033[1;35m --:: {}\033[1;31mRESPONSE END{} \033[1;34m::--\033[0m'.format(Fore.GREEN,96 Style.RESET_ALL, Back.GREEN + Style.BRIGHT, Style.RESET_ALL))97 return True98 def PrintProgress(self, password, ip, request, response):99 if self.verbose == 0:100 self.PrintPassword(password)101 elif self.verbose == 1:102 self.PrintPassword(password)103 self.PrintResponse(response)104 elif self.verbose == 2:105 self.PrintPassword(password)106 self.PrintResponse(response)107 self.PrintIPAddress(ip)108 else:109 self.PrintPassword(password)110 self.PrintRequest(request)111 self.PrintResponse(response)112 self.PrintIPAddress(ip)113 return True114 def ReportAttack(self, password):115 print('\n\033[1;32m[\033[1;35m{}+{}\033[1;32m] --:: {}\033[1;32mCompleted -> @{} {} \033[1;33m::--\033[0m'.format(Fore.YELLOW,116 Style.RESET_ALL, Back.YELLOW + Style.BRIGHT, self.username, Style.RESET_ALL),117 end='')118 if not password == None:119 print('{}\033[1;33m[{}\033[1;31mâ{}{}\033[1;33m]{} {}\033[1;33mPassword Found!{} :: {}\033[0m'.format(Style.BRIGHT,120 Fore.RED,121 Style.RESET_ALL,122 Style.BRIGHT,123 Style.RESET_ALL,124 Fore.CYAN,125 Style.RESET_ALL + Style.BRIGHT + Fore.GREEN,126 password + Style.RESET_ALL127 ))128 else:129 print('{}\033[1;32m[\033[1;31m!!{}\033[1;32m]\033[1;31mPassword not found , Try using another wordlist.{}\033[0m'.format(130 Style.BRIGHT, Fore.RED, Style.RESET_ALL))131 print('{}\033[1;31m[{}\033[1;35m+{}{}\033[31m]{} {}\033[1;32mFinnished in {}{}\033[0m'.format(Style.BRIGHT,132 Fore.YELLOW,133 Style.RESET_ALL,134 Style.BRIGHT,135 Style.RESET_ALL,136 Fore.MAGENTA,137 Style.RESET_ALL + Fore.YELLOW,138 str(datetime.datetime.now(139 ) - self.started) + Style.RESET_ALL140 ))141 return True142 def PrintFooter(self):143 print('\n{}\033[1;35mGithub:->>{}{}\033[1;31mhttps://github.com/BHUTUU/IG-BHUTUU{}\033[0mm'.format(Fore.GREEN,144 Style.RESET_ALL,145 Style.BRIGHT,146 Style.RESET_ALL147 ))...
temp.py
Source:temp.py
1from colorama import *2SCREEN=2003def view_colours():4 print(Fore.WHITE + Back.BLACK + Style.BRIGHT + " ".center(SCREEN)+Style.RESET_ALL)5 print(Fore.WHITE + Back.BLUE + Style.BRIGHT + " ".center(SCREEN)+Style.RESET_ALL)6 print(Fore.WHITE + Back.CYAN + Style.BRIGHT + " ".center(SCREEN)+Style.RESET_ALL)7 print(Fore.WHITE + Back.GREEN + Style.BRIGHT + " ".center(SCREEN)+Style.RESET_ALL)8 print(Fore.WHITE + Back.LIGHTBLACK_EX + Style.BRIGHT + " ".center(SCREEN)+Style.RESET_ALL)9 print(Fore.WHITE + Back.LIGHTBLUE_EX + Style.BRIGHT + " ".center(SCREEN)+Style.RESET_ALL)10 print(Fore.WHITE + Back.LIGHTCYAN_EX + Style.BRIGHT + " ".center(SCREEN)+Style.RESET_ALL)11 print(Fore.WHITE + Back.LIGHTGREEN_EX + Style.BRIGHT + " ".center(SCREEN)+Style.RESET_ALL)12 print(Fore.WHITE + Back.LIGHTMAGENTA_EX + Style.BRIGHT + " ".center(SCREEN)+Style.RESET_ALL)13 print(Fore.WHITE + Back.LIGHTRED_EX + Style.BRIGHT + " ".center(SCREEN)+Style.RESET_ALL)14 print(Fore.WHITE + Back.LIGHTWHITE_EX + Style.BRIGHT + " ".center(SCREEN)+Style.RESET_ALL)15 print(Fore.WHITE + Back.LIGHTYELLOW_EX + Style.BRIGHT + " ".center(SCREEN)+Style.RESET_ALL)16 print(Fore.WHITE + Back.MAGENTA + Style.BRIGHT + " ".center(SCREEN)+Style.RESET_ALL)17 print(Fore.WHITE + Back.RED + Style.BRIGHT + " ".center(SCREEN)+Style.RESET_ALL)18 print(Fore.WHITE + Back.WHITE + Style.BRIGHT + " ".center(SCREEN)+Style.RESET_ALL)19 print(Fore.WHITE + Back.YELLOW + Style.BRIGHT + " ".center(SCREEN)+Style.RESET_ALL)20 21def view_colours2():22 print(Fore.WHITE + Back.LIGHTWHITE_EX + Style.BRIGHT + " ".center(SCREEN)+Style.RESET_ALL)23 print(Fore.WHITE + Back.MAGENTA + Style.BRIGHT + " ".center(SCREEN)+Style.RESET_ALL)24 print(Fore.WHITE + Back.LIGHTMAGENTA_EX + Style.BRIGHT + " ".center(SCREEN)+Style.RESET_ALL)25 print(Fore.WHITE + Back.LIGHTCYAN_EX + Style.BRIGHT + " ".center(SCREEN)+Style.RESET_ALL)26 print(Fore.WHITE + Back.LIGHTBLUE_EX + Style.BRIGHT + " ".center(SCREEN)+Style.RESET_ALL)27 print(Fore.WHITE + Back.LIGHTBLACK_EX + Style.BRIGHT + " ".center(SCREEN)+Style.RESET_ALL)28 print(Fore.WHITE + Back.LIGHTGREEN_EX + Style.BRIGHT + " ".center(SCREEN)+Style.RESET_ALL)29 print(Fore.WHITE + Back.RED + Style.BRIGHT + " ".center(SCREEN)+Style.RESET_ALL)30 print(Fore.WHITE + Back.LIGHTRED_EX + Style.BRIGHT + " ".center(SCREEN)+Style.RESET_ALL)31 print(Fore.WHITE + Back.LIGHTYELLOW_EX+ Style.BRIGHT + " ".center(SCREEN)+Style.RESET_ALL)32 print(Fore.WHITE + Back.YELLOW + Style.BRIGHT + " ".center(SCREEN)+Style.RESET_ALL)33 34# view_colours()35print ()36view_colours2()...
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!!