''' 2021-05-22 To Dead Code Copyright Brett Paufler Previously Entitled: utilities_txt_files_refactored The _refactored meant that I had already moved a working file over This is a dead file # # # Created on May 27, 2019 @author: DATA Extracts and pre-formarts txt and md files To be used in next step: Must have Title on first line ''' from os import listdir from os.path import join as path_join def get_list_of_txt(dir_in = '.\\input\\'): '''Returns a list of markdown (.md) files in input directory''' list_of_emails = [path_join(dir_in, f) for f in listdir(dir_in) if f.endswith('.md') or f.endswith('.txt')] return list_of_emails def get_raw_text_txt(path_to_md): '''Extract text from md or txt files''' with open(path_to_md, 'r') as f: raw_md_text = f.read() return raw_md_text def strip_raw_text_txt(raw_email_text): '''Removes blank lines from raw_md_text''' line_items = raw_email_text.split('\n') no_blank_lines = [i for i in line_items if i != ''] stripped_text = '\n'.join(no_blank_lines) return stripped_text def text_iterator_txt(): '''Sequentially yields text of all md or txt in ./input''' for next_file_path in get_list_of_txt(): raw_text = get_raw_text_txt(next_file_path) working_text = strip_raw_text_txt(raw_text) yield working_text