/*
 Name:  SECIDX.CMD

 Description:Retrieve SEC archived and current index files beginning a given year

 Author:  HG 5/21/01, modifications (untested) by BAM 5/21/01

 Comment: None

 Usage:  Run in OS/2 CMD session

 Arguments: None

 Output:  None

 Bugs:  None

 Fixes:  None
*/

/* beginning year */
beginningYear = 2000

/* Local directories */
localDir = "F:\SEC\"

/* server information */
hostURL = "ftp://ftp.sec.gov"
hostDir = "/edgar/"

/* Define location of external programs required for execution */
executeWGET = "F:\wget\os2\wget"
executePKZIP = "F:\OS2Utils\PKZipOS2\PKZip"

/* install REXX function library */
rc = RxFuncAdd( "SysSleep", "RexxUtil", "SysSleep" )
say "REXX function library load return code:" rc

/* Save the current directory */
CurrDir = directory()

/* get today's  date in standard format, i.e., YYYYMMDD */
today = date( s )

/* retrieve year and month from date */
currentYear = left( today, 4 )
currentMonth = substr( today, 5, 2 )

/* download archived index files */
do year = beginningYear to currentYear by 1

 /* create host directory name */
 dir = hostDir || "full-index/" || year || "/"

 /* mirror index files and remove one level of directories */
 /* wget options: use recursion, file mask, timestamp, no DNS search, and remove one level of directories */
 fileMask = "master.zip"
 executeWGET || " -r -A " || fileMask || " -N -nH --cut-dirs=1" hostURL || dir
end

/* calculate range of daily files needed */

select

   when ( currentMonth <= 3  ) then beginningMonth = 1
   when ( currentMonth <= 6  ) then beginningMonth = 4
   when ( currentMonth <= 9  ) then beginningMonth = 7
   when ( currentMonth <= 12  ) then beginningMonth = 10

   otherwise say "Warning -- Invalid current month:" currentMonth

end  /* select */

/* mirror daily index files and remove one level of directories */
/* wget options: use one level recursion, file mask, timestamp, no DNS search, and remove one level of directories */

dir = hostDir || "daily-index/"
do month = beginningMonth to currentMonth by 1
 month = right( month, 2, "0" )
 fileMask = "master." || currentYear || month || "*.idx"
 executeWGET || " -r -l 1 -A " || fileMask || " -N -nH --cut-dirs=1" hostURL || dir
end

/* search directory for index files */
rc = SysFileTree( localDir || "*.zip", documents, "FS" )
if ( rc > 0 ) then do
 say "Building tree with index files failed..." rc
end

/* report number of matching index files */
say documents.0 || " index files found"

/* loop through each file and unpack data if it needs to be updated */

if ( documents.0 > 0 ) then do
 do i = 1 to documents.0
  parse var documents.i date time size flags fullName
  say "Unpacking file" i "of" documents.0 ":" fullName

  /* extract directory */
  temp = filespec( "p", fullName )
  dir = left( temp, length( temp ) - 1 )

  /* change directory */
  rc = directory( dir )

  /* update file */
  executePKZIP || " /extract=upd " || fullName
 end
end

/* Restore the current directory */

rc = directory( CurrDir )

/* exit program */
exit

Rexx Group Charter
Lesson 1 | Lesson 2 | Lesson 3 | Lesson 4
Exercises 1 | Exercises 2 | Exercises 3
Answers to exercises
Exercises 1
Example code
Stock Market | Stock Market_a


About these pages
Content updated: 07-09-2005 10:27am

Page building by: PPWizard Content updated
07-09-2005 10:27am
Valid HTML 4.01!Valid CSS!