#How well you know your computer #Here are questions for jaahas.py which is the core of the programm import lxml #pip install lxml import platform #core module import cpuinfo #pip install py-cpuinfo import psutil #pip install psutil import pandas as pd #pip install pandas import re #core module import subprocess #core module import random #core module import datetime #core module #Appended game questions: Questions = [] #SYSTEM operating_system_list = ["Windows","MacOs", "Linux", "Android"] operating_system = platform.system() if operating_system in operating_system_list: operating_system_list.remove(operating_system) operating_system2 = operating_system_list[-1] operating_system3 = operating_system_list[-2] operating_system4 = operating_system_list[-3] Questions.append({ "question": "What operating system are you running?", "choices": [operating_system,operating_system2, operating_system3, operating_system4], "answer": operating_system }) else: operating_system2 = operating_system_list[-1] operating_system3 = operating_system_list[-2] operating_system4 = operating_system_list[-3] Questions.append({ "question": "What operating system are you running?", "choices": [operating_system,operating_system2, operating_system3, operating_system4], "answer": operating_system }) #How long from last boot boot_time_list = [] boot_time = subprocess.check_output('systeminfo | findstr "Time:"', shell=True, universal_newlines=True) #Runs command trough cmd if len(boot_time) > 0: boot_time = (str(boot_time).replace("System Boot Time:","").replace(" ","").replace("\n","").split(",")) boot_time_list.append(boot_time) time_boot = (boot_time_list[0][1]) current_date = (boot_time_list[0][0]) if str(current_date).find("/") > 0: current_date1 = str(current_date).split("/") else: #Date can also be separated with / or . depending on system settings current_date1 = str(current_date).split(".") current_day = current_date1[0] clock = (boot_time_list[0][1]) #Have to count even days if some user has fast sartup on and their cpu dosen't boot normally time_now = (datetime.datetime.now()) extra = ((int(time_now.day)-int(current_day))*24) #days in hours added at the end if str(time_boot).find(":") > 0: time_boot2 = (str(time_boot).split(":")) else: #Time can be printed with . or : depending on system settings mainly noticable between windows 10 and 11 time_boot2 = (str(time_boot).split(".")) hours = int(time_now.hour)-int(time_boot2[0])+extra minutes = int(time_now.minute)-int(time_boot2[1]) seconds = int(time_now.second)-int(time_boot2[2]) if minutes < 0: hours=hours-1 #take current time and boot time and substract them minutes=minutes+60 if seconds < 0: seconds = seconds+60 minutes = minutes-1 if minutes < 0: minutes = minutes+60 hours = hours -1 answer = (hours,"h",minutes,"min",seconds,"s") answer1 = (hours,"h",46,"min",44,"s") if answer1 == answer: answer1 = (hours,"h",12,"min",53,"s") answer2 = (hours+1,"h",14,"min",12,"s") if answer2 == answer: answer2 = (hours,"h",34,"min",2,"s") answer3 =(hours-1,"h",44,"min",34,"s") if answer3[0] < 0: answer3 = (hours,"h",44,"min",34,"s") if answer3 == answer: answer3 = (hours,"h",14,"min",12,"s") answer = str(answer).replace(",","").replace("'","").replace(" ","").replace(")","").replace("(","") answer1 = str(answer1).replace(",","").replace("'","").replace(" ","").replace(")","").replace("(","") answer2 = str(answer2).replace(",","").replace("'","").replace(" ","").replace(")","").replace("(","") answer3 = str(answer3).replace(",","").replace("'","").replace(" ","").replace(")","").replace("(","") Questions.append( { "question": "How long has your system been running?", "choices": [answer1,answer2,answer3,answer], "answer": answer } ) #Operating system install date install_list = [] Install_date = subprocess.check_output('systeminfo | findstr "Date:"', shell=True, universal_newlines=True) #Runs command trough cmd if len(Install_date) > 0: date = (Install_date.replace("Original Install Date:","").replace(" ","").replace("\n","").split(",")) install_list.append(date) if install_list[0][0].find("/") > 0: date2 = (install_list[0][0].split("/")) else: #Date can be separated by / or . date2 = (install_list[0][0].split(".")) year = int(date2[2]) #formating and removal of extra marks month = int(date2[1]) day = int(date2[0]) date2 = str(date2).replace(" ","/").replace("[","").replace("]","").replace(",","").replace("'","") Install_date1 = abs(day-13),"/",abs(month-2),"/",year Install_date11 = (str(Install_date1).replace("'","").replace(",","").replace(" ","").replace("(","").replace(")","")) Install_date2 = abs(day-29),"/",abs(month-10),"/",year Install_date22 = (str(Install_date2).replace("'","").replace(",","").replace(" ","").replace("(","").replace(")","")) Install_date3 = abs(day-3),"/",abs(month-5),"/",year Install_date33 = (str(Install_date3).replace("'","").replace(",","").replace(" ","").replace("(","").replace(")","")) Questions.append( #You can minus max of 29 from day and 13 from month, year is kept the same to raise difficulty { "question": "When did you install your Os?", "choices": [Install_date11,Install_date22, date2, Install_date33], "answer": date2 } ) else: pass #CPU my_cpuinfo = cpuinfo.get_cpu_info() cpu = my_cpuinfo['brand_raw'] intel = 'Intel' match = re.search(intel, cpu) #Look if Intel is in brand_raw if match: #Removing extra info from Intel cpus cpu1=cpu.replace("(R)","").replace("(TM)","").replace("CPU","").replace(" "," ") amd = 'AMD' match = re.search(amd, cpu) #Look if AMD is in brand_raw if match: #Removing extra info from AMD cpus cpu1=(cpu.replace(" Six-Core Processor","").replace(" 8-Core Processor","").replace(" Ten-Core Processor","") .replace(" Four-Core Processor","").replace(" 16-Core Processor","").replace(" Eight-Core Processor","") .replace(" 24-Core Processor","").replace(" 12-Core Processor","").replace(" 6-Core Processor","") .replace(" 10-Core Processor","").replace(" 2-Core Processor","").replace(" "," ")) else: #From this project I have learned never to touch AMD they do everything so much harder pass cpus = pd.read_html('https://www.cpubenchmark.net/cpu_list.php')[0] #Web scrape table from url cpus = cpus.loc[:, ['CPU Name']] #Remove excess table columns for clarity cpus['row'] = cpus.index #Assign each row a ascending number cpus.row = cpus.row.astype(str) #Change dataframe type select_cpu = cpus.loc[cpus['CPU Name'] == cpu1] #Check if your cpu is in the table if len(select_cpu) != 0: #Check if your cpu was on table selected_row = (select_cpu['row'].to_string(index=False)) #Remove extra info that is printed out on default cpu2=(cpus["CPU Name"].iloc[[int(selected_row)-1]].to_string(index=False,header=False)) #From your cpu move up and down cpu3=(cpus["CPU Name"].iloc[[int(selected_row)-2]].to_string(index=False,header=False)) #on the table to choose cpu4=(cpus["CPU Name"].iloc[[int(selected_row)+1]].to_string(index=False,header=False)) #alernative answers as other choices Questions.append({ #Append question if cpu is found in the table "question": "Which CPU is yours?", "choices": [cpu4,cpu2, cpu1, cpu3], "answer": cpu1 }) else: pass #CPU CORES cpu_core_list=[16,24,32,64] cpu_cores = int(my_cpuinfo['count']) if cpu_cores < 12: cpu_cores2 = cpu_cores+2 #wrong answers trying to be close cpu_cores3 =cpu_cores-2 #to the answer and common ammount of cores cpu_cores4 =cpu_cores-4 if cpu_cores4 < 2: cpu_cores4 == cpu_cores2+2 Questions.append({ "question": "How many CPU logical cores do you have?", "choices": [cpu_cores2, cpu_cores3, cpu_cores, cpu_cores4], "answer": cpu_cores }) if cpu_cores == 12: cpu_cores2 = 10 cpu_cores3 = 8 cpu_cores4 = 16 Questions.append({ "question": "How many CPU cores do you have?", "choices": [cpu_cores2, cpu_cores3, cpu_cores, cpu_cores4], "answer": cpu_cores }) if cpu_cores > 12: if cpu_cores in cpu_core_list: cpu_core_list.remove(cpu_cores) cpu_cores2 = cpu_core_list[0] cpu_cores3 = cpu_core_list[1] cpu_cores4 = cpu_core_list[2] Questions.append({ "question": "How many CPU cores do you have?", "choices": [cpu_cores2, cpu_cores3, cpu_cores, cpu_cores4], "answer": cpu_cores }) #RAM ram_list = [4,8,16,32,64,128] total_ram =int((round(psutil.virtual_memory().total/1024**3))) #RAM can be +- ~ 0.2 of the adverized amount if total_ram in ram_list: #Takes amount of RAM and rounds it to GB ram_list.remove(total_ram) if total_ram >= 64: total_ram2 = ram_list[2] #Try to get common RAM ammounts total_ram3 = ram_list[3] #as wrong answers total_ram4 = ram_list[4] Questions.append({ "question": "How many gigabytes of RAM do you have?", "choices": [total_ram3,total_ram2, total_ram, total_ram4], "answer": total_ram }) if total_ram <= 16: total_ram2 = ram_list[0] total_ram3 = ram_list[1] total_ram4 = ram_list[2] Questions.append({ "question": "How many gigabytes of RAM do you have?", "choices": [total_ram3,total_ram2, total_ram, total_ram4], "answer": total_ram }) else: total_ram2 = ram_list[1] total_ram3 = ram_list[2] total_ram4 = ram_list[3] Questions.append({ "question": "How many gigabytes of RAM do you have?", "choices": [total_ram3,total_ram2, total_ram, total_ram4], "answer": total_ram }) ram_usage = psutil.virtual_memory().percent if type(ram_usage) != None: #If ram_usage has been acquired type shouyln't be None ram_usage1 = (int(ram_usage)-11.3),"%" if (str(ram_usage1).find("-")) == True: #Check if ram is minus ram_usage1 = (int(ram_usage)+11.3),"%" ram_usage2 = (int(ram_usage)-21.4),"%" if (str(ram_usage2).find("-")) == True: #Check if ram is minus ram_usage2 = (int(ram_usage)+11.3),"%" ram_usage3 = (int(ram_usage)+9.9),"%" if len(str(ram_usage3)) >= 12: #Check if ram is 3 digit / over 100% ram_usage3 = (int(ram_usage)-11.3),"%" ram_usage = ram_usage,"%" Questions.append({ #Append question "question": "What was your RAM usage at launch?", "choices": [ram_usage,ram_usage1,ram_usage2,ram_usage3 ], "answer": ram_usage }) #GPU def get_gpu(): line_as_bytes = subprocess.check_output("nvidia-smi -L", shell=True) #Gets gpu model name line = line_as_bytes.decode("ascii") _, line = line.split(":", 1) line, _ = line.split("(") return line.strip() #Makes it beatiful and gets rid of extras gpu1 = (get_gpu().replace("NVIDIA ","").replace("(R)","").replace("Graphics ","").replace("AMD ","").replace("(TM) ","")) gpus = pd.read_html('https://www.videocardbenchmark.net/gpu_list.php')[0] #Web scrapes a table of gpus and makes it dataframe gpus = gpus.loc[:, ['Videocard Name']] #Removes not needed columns from the table gpus['row'] = gpus.index #Assigns number to each row and gpu gpus.row = gpus.row.astype(str) #change type to str select_gpu = gpus.loc[gpus['Videocard Name'] == gpu1] #Tries to find you gpu from the table selected_row2 = (select_gpu['row'].to_string(index=False)) #Gets rid of extra output gpus2 = gpus[gpus['Videocard Name'].str.contains("(Mobile) | Laptop GPU | with Max-Q Design") == False] #Gets rid of unwanted versions gpu2=(gpus2["Videocard Name"].iloc[[int(selected_row2)-1]].to_string(index=False,header=False)) gpu3=(gpus2["Videocard Name"].iloc[[int(selected_row2)-2]].to_string(index=False,header=False)) #Chooses wrong answers gpu4=(gpus2["Videocard Name"].iloc[[int(selected_row2)+1]].to_string(index=False,header=False)) if len(select_cpu) > 0: #append question if gpu is found in the table on the website Questions.append({ "question": "Which GPU is yours?", "choices": [gpu4,gpu2,gpu3,gpu1 ], "answer": gpu1 }) else: pass #MOTHERBOARD motherboard_list = ["Asus TUF Z370 Plus Gaming","Z370 GAMING PLUS","MPG B550 GAMING PLUS", "ROG STRIX X670E-E","Gigabyte B650M AORUS ELITE AX","TUF Z370 Plus Gaming", #List of question choices "GA-Z170X-Gaming 7","ROG Strix Z370-H Gaming","MSI X370 GAMING PLUS", "ROG STRIX B450-E GAMING","Asus PRIME X670E-PRO","Z97-Gaming 3", "Z170A SLI PLUS","Intel DB75EN","GA-Z97MX-Gaming 5"] def motherboard(command): result = subprocess.run(command, capture_output=True, text=True) #Tries to get your motherboard output = result.stdout.strip() #name and save it in a variable return output #Chooses wrong answers from list and removes lots of potential extra marks motherboards1 = motherboard("wmic baseboard get product").replace("Product","").replace("\n","").replace(" ", "").replace("(", "").replace(")", "") motherboards2 = str(random.sample(motherboard_list,1)).replace("{","").replace("}","").replace("[","").replace("]","").replace("'","") motherboards3 = str(random.sample(motherboard_list,1)).replace("{","").replace("}","").replace("[","").replace("]","").replace("'","") motherboards4 = str(random.sample(motherboard_list,1)).replace("{","").replace("}","").replace("[","").replace("]","").replace("'","") while motherboards3 == motherboards2: motherboards3 = str(random.sample(motherboard_list,1)).replace("{","").replace("}","").replace("[","").replace("]","").replace("'","") while motherboards4 == motherboards2 or motherboards4 == motherboards3: motherboards4 = str(random.sample(motherboard_list,1)).replace("{","").replace("}","").replace("[","").replace("]","").replace("'","") if len(motherboards1) > 0: #Append motherboards if motherboard was acquired else don't add a question Questions.append({ "question": "Which of these is your motherboard?", "choices": [motherboards1,motherboards2,motherboards3,motherboards4], "answer": motherboards1 }) else: pass #STORAGE DISKS def get_storage(command): result = subprocess.run(command, capture_output=True, text=True) #Tries to get your storage disk output = result.stdout.strip() #model and save it in a variable return output storagedisk1 = str(get_storage("wmic diskdrive get model").replace("Model","")) storage_size = str(get_storage("wmic diskdrive get size").replace("Size","")) #Disk size(s) def remove_empty_lines(text): #Removes empty lines for clarity lines = text.split("\n") non_empty_lines = [line for line in lines if line.strip() != ""] return "\n".join(non_empty_lines) storage_size_list = [] storage_size_list.append(remove_empty_lines((storage_size)).replace(" ","").replace("\n"," ").split(" ")) size_list = storage_size_list[0] #Need to remove an extra list combined_size = sum([eval(i) for i in size_list]) #Adding device sizes together storage_sizes = round(combined_size/1024**3) if len(str(storage_sizes)) <= 0: #Don't append question if storage data hasn't been acquired pass if len(str(storage_sizes)) < 4: #For computers that have gigabytes or less of storage storage_sizes2 = storage_sizes-64 storage_sizes3 = storage_sizes+112 storage_sizes3 = storage_sizes+141 Questions.append({ "question": "How much is your total disk space?", "choices": [str(storage_sizes)+"GB",str(storage_sizes2)+"GB",str(storage_sizes3)+"GB",str(storage_sizes3)+"GB" ], "answer": storage_sizes }) if len(str(storage_sizes)) >= 4: #For computers that have terabytes or more of storage storage_sizes = round(storage_sizes/1024,3) storage_sizes2 = round(storage_sizes-0.334,3) storage_sizes3 = round(storage_sizes+0.691,3) storage_sizes4 = round(storage_sizes+0.298,3) Questions.append({ "question": "How much is your combined disk space?", "choices": [str(storage_sizes)+" TB",str(storage_sizes2)+" TB",str(storage_sizes3)+" TB",str(storage_sizes4)+" TB" ], "answer": str(storage_sizes)+" TB" }) storagedisk = (remove_empty_lines(storagedisk1)) #Model name disk_ammount = storagedisk.count("\n")+1 #Counts how many storage devices connected disk_ammount2 = disk_ammount+1 disk_ammount3 = disk_ammount+2 disk_ammount4 = disk_ammount-1 if disk_ammount4 <= 0: disk_ammount4 == disk_ammount+3 if len(storagedisk) > 0: #append question if storage disk is found Questions.append({ "question": "How many storage disks do you have?", "choices": [disk_ammount4,disk_ammount3,disk_ammount2,disk_ammount ], "answer": disk_ammount }) disk_list = [] storagedisks = (storagedisk.split("\n")) disk_list.append(storagedisks) #Randomly choose one of your disks random_disk = random.choice(disk_list[0]) disk_list2 = ["Kingston SSD A400 120GB","Kingston M.2 SSD KC3000 512GB ","Samsung SSD 870 EVO 2TB", "Seagate HDD BarraCuda 2TB","Samsung M.2 SSD 970 EVO Plus 1TB","Samsung SSD 770 EVO 250GB", #Question choices "Samsung SSD 840 EVO 500GB","Kingston SSD A400 960GB","Seagate HDD Exos X20 500GB", "WD HDD Red Plus 2TB","Kingston M.2 SSD FURY Renegade 500GB ","Samsung SSD 990 EVO 500GB"] if random_disk in disk_list2: disk_list2.remove(random_disk) random_disk2 = str(random.sample(disk_list2,1)).replace("{","").replace("}","").replace("[","").replace("]","").replace("'","") if random_disk2 in disk_list2: disk_list2.remove(random_disk2) #Determine question choices random_disk3 = str(random.sample(disk_list2,1)).replace("{","").replace("}","").replace("[","").replace("]","").replace("'","") if random_disk3 in disk_list2: disk_list2.remove(random_disk3) random_disk4 = str(random.sample(disk_list2,1)).replace("{","").replace("}","").replace("[","").replace("]","").replace("'","") if random_disk4 in disk_list2: disk_list2.remove(random_disk4) Questions.append({ "question": "Which of these is yours?", "choices": [random_disk2,random_disk3,random_disk4,random_disk ], "answer": random_disk }) def randomizer(): #Randomize order of answers Questions[0]['choices'] = random.sample(Questions[0]['choices'],len(Questions[0]['choices'])) Questions[1]['choices'] = random.sample(Questions[1]['choices'],len(Questions[1]['choices'])) Questions[2]['choices'] = random.sample(Questions[2]['choices'],len(Questions[2]['choices'])) Questions[3]['choices'] = random.sample(Questions[3]['choices'],len(Questions[3]['choices'])) Questions[4]['choices'] = random.sample(Questions[4]['choices'],len(Questions[4]['choices'])) Questions[5]['choices'] = random.sample(Questions[5]['choices'],len(Questions[5]['choices'])) Questions[6]['choices'] = random.sample(Questions[6]['choices'],len(Questions[6]['choices'])) Questions[7]['choices'] = random.sample(Questions[7]['choices'],len(Questions[7]['choices'])) try: Questions[8]['choices'] = random.sample(Questions[8]['choices'],len(Questions[8]['choices'])) except: pass try: Questions[9]['choices'] = random.sample(Questions[9]['choices'],len(Questions[9]['choices'])) except: pass #Try and except here for randomizer if question is skiped try: Questions[10]['choices'] = random.sample(Questions[10]['choices'],len(Questions[10]['choices'])) except: pass try: Questions[11]['choices'] = random.sample(Questions[11]['choices'],len(Questions[11]['choices'])) except: pass randomizer()