Best Python code snippet using tox_python
main.py
Source:main.py
1import os2import shutil3import uuid4from datetime import datetime5def get_unique_file(file):6 new_file = file.split('.')7 new_file.insert(-1, str(uuid.uuid4()))8 new_file = '.'.join(new_file)9 return new_file10#directories to send the files to, create the directories if they do not exist11target_dir = "C:/Users/Hammad/Downloads/"12target_dir_contents = os.listdir(target_dir)13pictures_dir = "Pictures/"14docs_dir = "Documents/"15videos_dir = "Videos/"16audio_dir = "Audios/"17other_dir = "Other Files/"18if not os.path.isdir(os.path.join(target_dir, pictures_dir)):19 os.mkdir(os.path.join(target_dir, pictures_dir))20 print("Pictures directory created")21if not os.path.isdir(os.path.join(target_dir, docs_dir)):22 os.mkdir(os.path.join(target_dir, docs_dir))23 print("Documents directory created")24if not os.path.isdir(os.path.join(target_dir, videos_dir)):25 os.mkdir(os.path.join(target_dir, videos_dir))26 print("Videos directory created")27if not os.path.isdir(os.path.join(target_dir, audio_dir)):28 os.mkdir(os.path.join(target_dir, audio_dir))29 print("Audio directory created")30if not os.path.isdir(os.path.join(target_dir, other_dir)):31 os.mkdir(os.path.join(target_dir, other_dir))32 print("Other directory created")33# filters between files and directories34dirs_list = []35files_list = []36for x in target_dir_contents:37 if os.path.isdir(os.path.join(target_dir, x)):38 dirs_list.append(x)39 40 if os.path.isfile(os.path.join(target_dir, x)):41 files_list.append(x)42#Moving files into their respective directories43#Check if a file with the same name is present in the directory to be moved, if found, then append the file with a uuid and then move44for file in files_list:45 if file.lower().endswith(('.png', '.jpg', '.jpeg', '.gif')):46 if os.path.isfile(os.path.join(target_dir, pictures_dir, file)):47 shutil.move(os.path.join(target_dir, file), os.path.join(target_dir, pictures_dir, get_unique_file(file)))48 else:49 shutil.move(os.path.join(target_dir, file), os.path.join(target_dir, pictures_dir, file))50 elif file.lower().endswith(('.pdf', '.docx', '.txt', '.doc', '.pptx', '.xlsx')):51 if os.path.isfile(os.path.join(target_dir, docs_dir, file)):52 shutil.move(os.path.join(target_dir, file), os.path.join(target_dir, docs_dir, get_unique_file(file)))53 else:54 shutil.move(os.path.join(target_dir, file), os.path.join(target_dir, docs_dir, file))55 elif file.lower().endswith(('.mp4', '.mov', '.mkv', '.wmv')):56 if os.path.isfile(os.path.join(target_dir, videos_dir, file)):57 shutil.move(os.path.join(target_dir, file), os.path.join(target_dir, videos_dir, get_unique_file(file)))58 else:59 shutil.move(os.path.join(target_dir, file), os.path.join(target_dir, videos_dir, file))60 elif file.lower().endswith(('.mp3', '.m4a', '.wma', '.flac', '.aac')):61 if os.path.isfile(os.path.join(target_dir, audio_dir, file)):62 shutil.move(os.path.join(target_dir, file), os.path.join(target_dir, audio_dir, get_unique_file(file)))63 else:64 shutil.move(os.path.join(target_dir, file), os.path.join(target_dir, audio_dir, file))65 else:66 if os.path.isfile(os.path.join(target_dir, other_dir, file)):67 shutil.move(os.path.join(target_dir, file), os.path.join(target_dir, other_dir, get_unique_file(file)))68 else:...
petandfamilyidentifier.py
Source:petandfamilyidentifier.py
...26 for i in range(len(pred)):27 st.markdown(f'**{pred[i].capitalize()}** with a probability of: **{probs[pred_idx][i]*100:.00f}%**')28def app():29 if platform.system() == 'Windows':30 learn = load_learner(get_unique_file('petandfamilyidentifier_windows_v4.pkl'), cpu=True)31 else:32 learn = load_learner(get_unique_file('petandfamilyidentifier_linux_v4.pkl'), cpu=True)33 # #st.set_page_config(layout="wide")34 st.title('Pet and Family identifier V2')35 st.header('Summary')36 st.markdown('The app was conceived with the idea of auto identifier my family\'s pets:heart_eyes:, and also some family members.:sweat_smile:')37 st.markdown('This version of the app has face washing powered by Streamlit.')38 st.markdown('Finally, it includes new functionality to handle multiple images at the same time. Also a section with examples below.')39 40 uploaded_files = st.file_uploader("Upload your photos", type = ['jpg','jpeg','png'],41 accept_multiple_files=True)42 43 photo_container = st.beta_expander("Results",expanded = True)44 45 with photo_container:46 col1, col2 = st.beta_columns(2)47 for uploaded_file in uploaded_files:48 with st.beta_container():49 col1, col2 = st.beta_columns(2)50 bytes_data = uploaded_file.read()51 img = PILImage.create(bytes_data)52 col1.image(img, use_column_width=True)53 pred,pred_idx,probs = learn.predict(img)54 col2.subheader('In this photo the model found:')55 for i in range(len(pred)):56 col2.markdown(f'**{pred[i].capitalize()}** with a probability of: **{probs[pred_idx][i]*100:.00f}%**')57 # col2.subheader('Is there an error? Select it please:')58 # for i in range(len(pred)):59 # an_error = col2.checkbox(f'{pred[i].capitalize()} is not in the photo')60 # if an_error:61 62 63 64 65 examples = st.beta_container()66 with examples:67 st.header('Examples')68 examples_containers = st.beta_columns(3)69 examples_images = [get_unique_file('new_sol.jpg'),70 get_unique_file('new_nexus.jpeg'),71 get_unique_file('new_nexus_jony.jpeg')]72 for example in range(len(examples_images)):73 show_example(examples_images[example], examples_containers[example], learn)74 ...
diff.py
Source:diff.py
...26 modes = parsed[2]27 label_A = parsed[3]28 label_B = args[3]29 for mode in modes:30 unique_file_A = get_unique_file(datatype, mode, label_A)31 unique_file_B = get_unique_file(datatype, mode, label_B)32 inputfile_A, outputfile_A = get_input_output_file(33 datatype, mode, label_A, 'sel/diff/events/%s' %label_B)34 inputfile_B, outputfile_B = get_input_output_file(35 datatype, mode, label_B, 'sel/diff/events/%s' %label_A)36 unique_file_A = get_unique_file(datatype, mode, label_A)37 unique_file_B = get_unique_file(datatype, mode, label_B)38 source = os.path.join(attr.srcselpath, 'DNTClass.C')39 ROOT.gROOT.ProcessLine('.L %s' % source )40 ROOT.gROOT.ProcessLine('DNTClass a("%s", "%s")'41 %(inputfile_A, outputfile_A))42 ROOT.gROOT.ProcessLine('a.Skim("%s")' %unique_file_A)43 sys.stdout.write('Save as %s \n' % outputfile_A) 44 ROOT.gROOT.ProcessLine('DNTClass b("%s", "%s")'45 %(inputfile_B, outputfile_B))46 ROOT.gROOT.ProcessLine('b.Skim("%s")' %unique_file_B)47 sys.stdout.write('Save as %s \n' % outputfile_B)48def get_unique_file(datatype, mode, label):49 evtname = '%s_%s_unqiue_%s.evt' %(datatype, mode, label)50 evtpath = os.path.join(attr.datpath, 'evt', label, 'events')51 unique_file = os.path.join(evtpath, evtname)52 return unique_file53 54def get_input_output_file(datatype, mode, label, outputdir): 55 datpath = attr.datpath56 if datatype == 'signal':57 inputname = mode+'.root'58 elif datatype == 'data':59 inputname = '*.root'60 else:61 raise NameError(datatype)62 outputname = mode+'.root'...
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!!