12345678910111213141516171819202122232425262728293031 |
- import os
- from service.trunks_service import TrunksService
- class FileReader:
- @staticmethod
- def find_and_print_split_files(directory):
- for root, dirs, files in os.walk(directory):
- for file in files:
- #if '_split_' in file and file.endswith('.txt'):
- if file.endswith('.md'):
- file_path = os.path.join(root, file)
- relative_path = '\\report\\' + os.path.relpath(file_path, directory)
- with open(file_path, 'r', encoding='utf-8') as f:
- lines = f.readlines()
- meta_header = lines[0]
- content = ''.join(lines[1:])
- TrunksService().create_trunk({'file_path': relative_path, 'content': content,'type':'community_report'})
- @staticmethod
- def process_txt_files(directory):
- for root, dirs, files in os.walk(directory):
- for file in files:
- if file.endswith('.txt'):
- file_path = os.path.join(root, file)
- with open(file_path, 'r', encoding='utf-8') as f:
- content = f.read()
- title = os.path.splitext(file)[0]
- TrunksService().create_trunk({'file_path': file_path, 'content': content, 'type': 'mr', 'title': title})
- if __name__ == '__main__':
- directory = '/Users/ycw/work/心肌梗死病历模版'
- FileReader.process_txt_files(directory)
|