def retrieve_document(file_path, directory='<STR_LIT>'):
ftp = FTP('<STR_LIT>', timeout=None)<EOL>ftp.login()<EOL>name = file_path.replace('<STR_LIT:/>', '<STR_LIT:_>')<EOL>if not os.path.exists(directory):<EOL><INDENT>os.makedirs(directory)<EOL><DEDENT>with tempfile.TemporaryFile() as temp:<EOL><INDENT>ftp.retrbinary('<STR_LIT>' % file_path, temp.write)<EOL>temp.seek(<NUM_LIT:0>)<EOL>with open('<STR_LIT>'.format(directory, name), '<STR_LIT>') as f:<EOL><INDENT>f.write(temp.read().decode("<STR_LIT:utf-8>"))<EOL><DEDENT>f.closed<EOL>records = temp<EOL>retry = False<EOL><DEDENT>ftp.close()<EOL>
This function takes a file path beginning with edgar and stores the form in a directory.
The default directory is sec_filings but can be changed through a keyword argument.