@@ -0,0 +1,1848 @@
+# This code will be designed to FTP into the sec.gov/edgar database %0A# and get the daily updated  index file%0A %0A# Information on SEC.gov ftp is available at:%0A# http://www.sec.gov/edgar/searchedgar/ftpusers.htm%0A%0A%0A%0A# importing%0A%0Aimport os%0A%0Aimport datetime%0A%0Aimport sys%0A%0Afrom ftplib import FTP%0A%0A%0A%0A# setting up the program to check for the date in the format that SEC.gov/edgar formats them%0A%0Afiledate = (datetime.date.today() - datetime.timedelta(days=1)).strftime('%25Y%25m%25d')%0A%0A%0A%0A%0A# The documents are in the format of form.YYYYMMDD.IDX %0A%0A# so now time = YYYYMMDD%0A%0A%0A%0A# I now define a variable newfile to be the title of the document of the day%0A%0Anewfile = 'form.' + filedate + '.idx'%0A%0A%0A# Testing newfile%0A%0Aprint(newfile + ' should be yesterday right?')%0A%0A%0A# Getting connected%0A%0A# Establish a connection to the server at: (fpt.http://www.sec.gov/edgar/daily-index) %0A# and/or ftp.http://www.sec.gov/edgar/full-index via FTP%0A%0A# log in as user %22anonymous,%22 using your electronic mail address as the password%0A%0A# defining and connecting to edgar with credentials%0A%0Aftp = FTP('ftp.sec.gov')%0Aftp.login('anonymous','michael@hdnfl.com')%0A%0Aprint('FTP session now open with ftp.sec.gov')%0A%0A%0A# change to the correct directory%0Aftp.cwd('/edgar/daily-index/')%0A%0Aprint('The current directory is now ftp.sec.gov/edgar/daily-index/')%0A%0A%0A# open local file so that we can copy data to it%0Alocal = open(newfile, 'wb')%0A%0A%0A# If our new index is in the files listed. this should download it and tell us.%0A%0A#%0A# This if loop does not save the file.%0A#%0A%0A            %0Aif newfile in ftp.nlst():%0A        ftp.retrbinary('RETR %25s' %25 newfile, local.write) and print (newfile + ' has been downloaded')%0Aelse:%0A        print ('It is either a weekend or stock holiday. No index document was released today')%0A%0A# Close the local file%0Alocal.close()%0A%0A# Close the connection%0Aftp.quit()%0A%0Aprint ('ftp is now closed')%0A

Create new_index.py