home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / wcst2url.zip / createURL.CMD < prev    next >
OS/2 REXX Batch file  |  1998-01-01  |  8KB  |  265 lines

  1. /*
  2.  *
  3.  * createURL v1.0 - (c) 1997
  4.  * Create URL Objects out of WarpCast News and place them in date-ordered
  5.  * subfolders inside the NEW and UPDATED folders created by createFOLDER
  6.  *
  7.  * G.Aprile A.Resmini P.Rossi
  8.  * resmini@netsis.it
  9.  *
  10.  * Needless to say, this is absolutely FREEWARE, comes with no
  11.  * warranties whatsoever, and does not work in Windows.
  12.  * Actually, you would need some 10MBs program to do this, in Windows.
  13.  * ;)
  14.  *
  15.  * G.Aprile and A.Resmini are members of teamOS2 Italy
  16.  *
  17.  * This Rexx procedure works within PMMail 1.9x.
  18.  * You need to set it as a rexx command for incoming mail.
  19.  * Open your account or utilities settings depending on your version of
  20.  * the program, get to the Rexx tab and enter the name of this file
  21.  * under the 'Message receive exit', complete with path.
  22.  * Mark the checkbox also, or it won't  work. ;)
  23.  *
  24.  * You will need the FILEREXX rexx extensions, available on Hobbes as
  25.  * filerx.zip in the \rexx directory.
  26.  *
  27.  */
  28.  
  29.     call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  30.     call SysLoadFuncs
  31.     call RxFuncAdd 'FileLoadFuncs', 'FILEREXX', 'FileLoadFuncs'
  32.     call FileLoadFuncs
  33.  
  34.  /* Let's set a bunch of variables and explain their use */
  35.  
  36.  /* This parses the file handle passed by PMMail */
  37.  
  38.     arg msgfile
  39.  
  40.  /* The msgline variables are used to handle lines in the message */
  41.  
  42.     msgline.0 = 3
  43.     msgline.1 = ''
  44.     msgline.2 = ''
  45.     msgline.3 = ''
  46.     lSubj = 0
  47.     lNew  = 0
  48.     lUpdated = 0
  49.  
  50.  /* This string lets you choose if you want URL objects or just a dat
  51.   * file for HTMLBuilder. Note that you always create the dat file
  52.   * and that if you choose no URLs, the folders created by createFOLDER
  53.   * are quite useless. Nothing gets written there.
  54.   * And if you do not want a dat file, do not use this program.
  55.   * Default is create them URLs.
  56.   *
  57.   * 0 = Create the URL objects
  58.   * 1 = No, thanks, I'll go for the dat file only
  59.   */
  60.  
  61.   URLorDAT = 0
  62.  
  63.  /*
  64.   * This value lets you choose between standard or Warp 4 URL folders
  65.   * for your URLs to be stored in. Default is standard folders.
  66.   *
  67.   * 0 = Standard folder
  68.   * 1 = URL folder
  69.   */
  70.  
  71.   FolderType = 0
  72.  
  73.  /*
  74.   * This is the name of the dat file we will use to generate the HTML
  75.   * with HTMLBuilder. Better leave it alone.
  76.   * Or rememeber you will have to change the reference in both files.
  77.   */
  78.  
  79.   datFile = 'wcastidx.dtf'
  80.  
  81.  /*
  82.   * These are the strings this script is looking for.
  83.   * Mind you that SUBJSTR is the one string which makes of a Warpcast msg
  84.   * a Warpcast URL message. If there is no such string, we are not  going
  85.   * to be bothered with it.
  86.   */
  87.  
  88.     subjStr = '[WarpCast] New and Updated Links at the Supersite for'
  89.     updStr =  'Monitored sites updated in the past 24 hours:'
  90.     newStr =  'New Sites recently added:'
  91.  
  92.  
  93.   /*
  94.    * Start of program
  95.    * Do not modify anything below this line unless you know what you are
  96.    * doing.
  97.    */ 
  98.  
  99.     If FolderType = 0 then 
  100.        cNameFolder = 'WPFolder'
  101.     else
  102.       cNameFolder = 'WPURLFolder'    
  103.  
  104.  /*
  105.   * Create the datFile used by HTMLBuilder
  106.   * This file is written ex novo every time a Warpcast URL message comes in
  107.   */
  108.  
  109.     handle = 0
  110.     handle = FileOpen(datFile,'rw','on')
  111.     if handle = 0 then
  112.      do
  113.        if FileClose(handle) = 0 then handle = 0
  114.        say ' Ah, we have an OS error while creating the file ' || datFile
  115.      end
  116.  
  117.      do while lines(msgfile)
  118.        msgline.2=linein(msgfile)
  119.  
  120.  /* Let's start checking the incoming message subject string */
  121.  
  122.        do while lSubj = 0 & lines(msgfile)
  123.  
  124.           if pos('Subject:',msgline.2) > 0 then
  125.              do
  126.                if pos(subjStr,msgline.2) > 0 then
  127.                 do
  128.                 lSubj = 1
  129.                 msgline.1 = msgline.2
  130.                 msgline.2 = linein(msgfile)
  131.                 VarDate = Substr(msgline.2,7,16)
  132.                 FolderDate = Substr(VarDate, 1, 1) || Substr(VarDate, 6, 2),
  133.                              || Substr(VarDate, 9, 1) || Substr(VarDate, 15, 2)
  134.                 err = FilePuts(handle, VarDate )
  135.                 end
  136.                else
  137.                 exit
  138.              end
  139.         msgline.1 = msgline.2
  140.         msgline.2 = linein(msgfile)
  141.        end
  142.  
  143.  /* Wow, it's the right message. Check if it has updated links */
  144.  
  145.        do while lUpdated=0 & lNew = 0 & lines(msgfile)
  146.           if pos(updStr,msgline.2) > 0 then
  147.              do
  148.              msgline.3 = '<WCASTUPD>'
  149.              lUpdated = 1
  150.               objectID  = '<UPD' || FolderDate || '>'
  151.               location  = '<WCASTUPD>'
  152.               Call CreateFolder
  153.              end
  154.           msgline.1 = msgline.2
  155.           msgline.2 = linein(msgfile)
  156.        end
  157.  
  158.  /* Well, we have the updated ones. Now check for the new string */
  159.  
  160.        do while lUpdate > 0 & lines(msgfile)
  161.  
  162.           if pos(newStr,msgline.2) > 0 then
  163.              do
  164.                msgline.3= '<WCASTNEW>'
  165.                lNew = 1
  166.                lUpdated = 0
  167.                objectID  = '<NEW' || FolderDate || '>'
  168.                location  = '<WCASTNEW>'
  169.                Call CreateFolder
  170.                leave
  171.              end
  172.           if pos('All Links',msgline.2) > 0 then exit
  173.           if pos('http:',msgline.2) > 0 then
  174.              do
  175.                err = FilePuts(handle, msgline.1 )
  176.                err = FilePuts(handle, msgline.2 )
  177.                err = FilePuts(handle, 'UpDated' )
  178.                if URLorDAT = 0 then
  179.                  do
  180.                   location = '<UPD' || FolderDate || '>'
  181.                   call createUrl
  182.                  end
  183.              end
  184.           msgline.1 = msgline.2
  185.           msgline.2 = linein(msgfile)
  186.        end
  187.  
  188.  /*
  189.   * Here come the new ones. Check for URLs up to the end of file
  190.   * but avoid the self referencing URLs at the end.
  191.   * We don't want to have a thousand OS2SS URLs. ;)
  192.   */
  193.  
  194.        do while lNew > 0 & lines(msgfile)
  195.  
  196.           if pos('All Links',msgline.2) > 0 then exit
  197.  
  198.           if pos('http:',msgline.2) > 0 then
  199.              do
  200.                err = FilePuts(handle, msgline.1 )
  201.                err = FilePuts(handle, msgline.2 )
  202.                err = FilePuts(handle, 'New' )
  203.                if URLorDAT = 0 then
  204.                   do
  205.                    location = '<NEW' || FolderDate || '>'
  206.                    call createUrl
  207.                   end
  208.              end
  209.  
  210.           msgline.1 = msgline.2
  211.           msgline.2 = linein(msgfile)
  212.        end
  213.  
  214.     end
  215.  
  216.     call FileDropFuncs
  217.     exit
  218.  
  219.  /* This is the procedure which actually creates the URL objects */
  220.  
  221.  CreateUrl:
  222.  
  223.        title  = msgline.1
  224.    className  = 'WPURL'
  225.        setup  = 'URL='|| msgline.2 || ';'
  226.    UpdateFlag = 'F'
  227.  
  228.     rc = SysCreateObject( className, title, location, setup , updateFlag )
  229.     if rc <> 1 then
  230.     do
  231.       say ' Wow, could not create the URL object for ' || title || '.' || '07'x
  232.       say ' Either the object already exists or an error occurred.'
  233.       say ''
  234.     end
  235.  
  236.     else
  237.       ExitCode = 0
  238.  
  239. return
  240.  
  241.   /* And this is the procedure which creates a new folder for each day */
  242.  
  243. CreateFolder:
  244.  
  245.      if URLorDAT = 0 then
  246.       do
  247.        title = VarDate
  248.        className = cNameFolder  
  249.       /*  if FolderType = 1 then classname = 'WPURLFolder' */
  250.        setup = 'OBJECTID=' || objectID || ';'
  251.        UpdateFlag = 'F'
  252.  
  253.        rc = SysCreateObject( className, title, location, setup, updateFlag )
  254.        if rc <> 1 then
  255.          do
  256.           say ' Wow, could not create the folder object for ' || Vardate || '.' || '07'x
  257.           say ' Either the object already exists or an error occurred.'
  258.           say ''
  259.        end
  260.       else
  261.       ExitCode = 0
  262.      end
  263.  
  264. return
  265.