Trademarks Project

From iMacros

Jump to: navigation, search

This project searches the US Patent and Trademarks Office website. Given an input search term it identifies which registrations meet certain criteria and then captures the contact details for those registrations.

Visual Basic Script:

 Option Explicit
 Dim iim1, iret, result, i
 Dim MailDate, DateRangeHi, DateRangeLo
 Dim  DocDescr, dateanddocstr, outputstr, outputline, headerline, dateline
 Dim dateanddocarray, outputarray, outputfieldarray, inputdatearray, LoArray, HiArray
 Dim filesys, outputfile, datefile, filesys1
 
 outputfieldarray = array("Name,", "Address Line 1,", "Address Line 2,", "Serial No,", "Mark,", "Mailing Date,")
 
 MsgBox ("This script is designed to search Trademarks.")
 
 'Intialise the output file
 Set filesys = CreateObject("Scripting.FileSystemObject") 
 Set outputfile= filesys.CreateTextFile("tmresults.csv")
 
 'Set up headers in outputfile
 For i=0 to UBound(outputfieldarray)
   headerline = headerline & outputfieldarray(i)
 Next 
 outputfile.writeline(headerline)
 
 'Read date file

 Set filesys1 = CreateObject("Scripting.FileSystemObject") 
 Set datefile = filesys1.OpenTextFile("tm_datefile.txt")
 dateline = datefile.ReadLine
 inputdatearray = split(dateline, ",")
 DateRangeLo = inputdatearray(0)
 DateRangeHi = inputdatearray(1)
 datefile.close()
 
 'Handle US date format in input file
 LoArray = split(DateRangeLo, "/")
 DateRangeLo = LoArray(1) & "/" & LoArray(0) & "/" & LoArray(2)
 HiArray = split(DateRangeHi, "/")
 DateRangeHi = HiArray(1) & "/" & HiArray(0) & "/" & HiArray(2)
 
 'Initialise iMacros
 set iim1= CreateObject ("InternetMacros.iim")
 iret = iim1.iimInit ("", TRUE)
 
 If iret < 0 then 
   MsgBox ("A problem was encountered running this script")
 End If
 'Run the first macro to search the trademarks.  Checking for the entry refusal screen.
 DO 
   iret = iim1.iimPlay("tm_search", 30)
   If iret < 0 Then 
     MsgBox  ("Error running Macro tm_search: "+ cstr (iret) +iim1.iimGetLastError())
   End If
 LOOP UNTIL iim1.iimGetLastExtract()="#EANF#[EXTRACT]"
 
 DO
 'For each document list
   DO
   'For each document in the list
     'Run the macro to check for the attorney record
     iret = iim1.iimPlay("tm_attorney_check")
     If iret < 0 Then
       MsgBox  ("Error running Macro tm_attorney_check: "+ cstr (iret) +iim1.iimGetLastError())
     End If
   
     'if an attorney of record is not found then 
     result = iim1.iimGetLastExtract
     If result = "#EANF#[EXTRACT]" Then
       'MsgBox  ("The attorney of record not found. Capturing further information.")
       ' Check the first document
       iret = iim1.iimPlay("tm_dateanddoc_check")
       If iret < 0 Then
         MsgBox  ("Error running Macro tm_dateanddoc_check: "+ cstr (iret) +iim1.iimGetLastError())
       End If 
       
       'parse the extract to get date and document title
       dateanddocstr = iim1.iimGetLastExtract()
       'MsgBox (dateanddocstr)
       dateanddocarray = split(dateanddocstr,"[EXTRACT]")
       
       ' variables required MailDate DocDescr
       MailDate = dateanddocarray(0)
       DocDescr = dateanddocarray(1)
       MailDate = FormatDateTime(MailDate)
                    
       'check date is in range and check document title
       If DateDiff("d",MailDate,DateRangeLo)<=0 and DateDiff("d",MailDate,DateRangeHi)>=0 Then
         If DocDescr="Offc Action Outgoing " Then
           'MsgBox ("It's an Offc Action Outgoing: " & Docdescr)
           'Extract the information
           iret = iim1.iimPlay("tm_extractinfo")
           If iret < 0 Then
             MsgBox  ("Error running Macro tm_extract_info: "+ cstr (iret) +iim1.iimGetLastError())
           End If 
           
           'Here is where we process the information
           outputstr = iim1.iimGetLastExtract()
           outputarray = split(outputstr,"[EXTRACT]")
           outputline = null
           outputarray(5) = MailDate
           If outputarray(4) = "" Then
             outputarray(4) = "Trademark Logo"
           End If
           For i=0 to UBound(outputarray)
               outputarray(i) = replace(outputarray(i), ",", "")
               outputline = outputline & outputarray(i) & ","
           Next
           outputfile.writeline(outputline) 
         End If                          
       End If
       
       'return to search results page
       iret = iim1.iimPlay("tm_backtoTESS")
       if iret < 0 Then
         MsgBox  ("Error running Macro tm_backtoTESS: "+ cstr (iret) +iim1.iimGetLastError())
       End If    
       
     End If
   
     'Proceed to next document
     iret = iim1.iimPlay("tm_next")
 
   LOOP UNTIL iret < 0 'end of pages check for specific code
    
   'Proceed to next list of documents
   iret = iim1.iimPlay("tm_nextlist")
 
 LOOP UNTIL iret < 0 'end of pages check for specific code
 
 iret = iim1.iimExit(1)
 if iret < 0 Then
    MsgBox  "Error exiting iMacros: "+ cstr (iret) +iim1.iimGetLastError()
 End If
 
 outputfile.close()
 
 WScript.Quit(0)

Macro code for tm_search.iim

 VERSION BUILD=5200622     
 TAB T=1     
 TAB CLOSEALLOTHERS 
 CMDLINE !DATASOURCE tm_search_terms.txt
 URL GOTO=http://www.uspto.gov/     
 SIZE X=876 Y=629    
 TAG POS=1 TYPE=A ATTR=TXT:Trademarks    
 TAG POS=1 TYPE=A ATTR=TXT:Search<SP>Trademarks 
 EXTRACT POS=1 TYPE=TXT ATTR=<H1>* 
 TAG POS=1 TYPE=A ATTR=TXT:Free<SP>Form<SP>Search<SP>(Advanced<SP>Search)   
 TAG POS=1 TYPE=TEXTAREA FORM=NAME:search_text ATTR=NAME:p_s_ALL CONTENT={{search_term}} 
 TAG POS=1 TYPE=INPUT:SUBMIT FORM=NAME:search_text ATTR=NAME:a_search&&VALUE:Submit<SP>Query  
 TAG POS=1 TYPE=A ATTR=TXT:7*   
 'Comment: New page loaded

Macro code for tm_attorney_check

 VERSION BUILD=5200622     
 TAB T=1      
 EXTRACT POS=1 TYPE=TXT ATTR=<B>Attorney*   

Macro code for tm_dateanddoc_check

 VERSION BUILD=5200622   
 SET !TIMEOUT 100    
 TAG POS=1 TYPE=IMG ATTR=TXT:<IMG<SP>alt="LINK<SP>TO<SP>TRADEMARK<SP>DOCUMENT<SP>RETRIEVAL"<SP>src="/webaka/icon/reg/tdr.gif"<SP>border=0>   
 EXTRACT POS=1 TYPE=TXT ATTR=<TD<SP>class=epoTableText<SP>id=maildate0<SP>noWrap<SP>align=left<SP>width="20%">*   
 EXTRACT POS=1 TYPE=TXT ATTR=<A<SP>onclick=*  

Macro code for tm_extractinfo

 VERSION BUILD=5200622  
 TAG POS=1 TYPE=A ATTR=TXT:Offc*   
 TAB T=2
 WAIT SECONDS=#DOWNLOADCOMPLETE#
 EXTRACT POS=1 TYPE=TXT ATTR=<A<SP>name=addr1>*   
 EXTRACT POS=1 TYPE=TXT ATTR=<A<SP>name=addr2>*   
 EXTRACT POS=1 TYPE=TXT ATTR=<A<SP>name=addr3>* 
 EXTRACT POS=1 TYPE=TXT ATTR=<A<SP>name=addr4>*   
 EXTRACT POS=1 TYPE=TXT ATTR=<A<SP>name=serno>*   
 EXTRACT POS=1 TYPE=TXT ATTR=<A<SP>name=mrk>*   
 EXTRACT POS=6 TYPE=TXT ATTR=<FONT<SP>size=4>*    

Macro code for tm_backtoTESS

 VERSION BUILD=5200622        
 TAB T=1  
 BACK     
 TAB CLOSEALLOTHERS
     

Macro code for tm_next

 VERSION BUILD=5200622     
 TAB T=1     
 TAG POS=1 TYPE=IMG ATTR=TXT:<IMG*doc_n.gif* 

Macro code for tm_nextlist

 VERSION BUILD=5200814     
 TAG POS=1 TYPE=IMG ATTR=TXT:<IMG<SP>src="/webaka/icon/reg/list_n.gif"<SP>border=0>   
 TAG POS=1 TYPE=A ATTR=TXT:7*