Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

adding a loop for a script, help :P

Posted on 2004-08-16
3
Medium Priority
?
341 Views
Last Modified: 2012-08-14
Hello.
I am trying to create a script that will pull some data from the amazon web services site.
I have most of it done, but i ran into a problem that i have no idea how to solve.

Here is the code:


<%@ LANGUAGE="VBSCRIPT" %>
<% Option Explicit
Dim aID, devToken, xmlURL, strASIN, strType, xmlHTTP, xmlDoc, arrDetails, i
Dim xmlResponse
Dim FSO
Dim myFile
set FSO = Server.CreateObject("scripting.FileSystemObject")
set myFile = fso.CreateTextFile("G:\test.txt", true)



'// Your Amazon Associates' ID
aID = "aspit-20"

'// Your Developers Token
devToken = "none"

'// The ASIN of the product
strASIN = "1590591062"

'// The type of search (lite|heavy)
strType = "lite"

'// XML URL
xmlURL = "http://xml.amazon.com/onca/xml3" & _
"?t=" & aID & _
"&dev-t=" & devToken & _
"&AsinSearch=" & strASIN & _
"&type=" & strType & _
"&f=xml"

'// Create the XMLHTTP object
Set xmlHTTP = Server.CreateObject("MSXML2.ServerXMLHTTP")

'// Fire off the request!
xmlHTTP.Open "GET", xmlURL, False
xmlHTTP.Send

'// Check if everything's okay
If xmlHTTP.Status = 200 Then
      xmlResponse = xmlHTTP.ResponseXML.xml

      '// Load the XML parser
      Set xmlDoc = Server.CreateObject("Microsoft.XMLDOM")
      xmlDoc.Async = False
      xmlDoc.loadXML (xmlResponse)
      
      '// Check for error message
      If IsBlank(xmlDoc.selectSingleNode("//ErrorMsg")) = False Then
            Response.Write "An error occurred. Sorry"
      Else
            '// Set the Details node
            Set arrDetails = xmlDoc.selectSingleNode ("//Details")
            
            '// Show product details
                  myFile.WriteLine( arrDetails.SelectSingleNode ("Asin").Text )  & vbtab & ( arrDetails.SelectSingleNode

("ProductName").Text ) & vbtab & ( arrDetails.SelectSingleNode ("ListPrice").Text ) & vbtab & ( arrDetails.SelectSingleNode

("OurPrice").Text ) & vbtab & ( arrDetails.SelectSingleNode ("UsedPrice").Text )


                  myFile.WriteLine( arrDetails.SelectSingleNode ("Asin").Text )


            Response.Write "<b>" & arrDetails.selectSingleNode ("ProductName").Text & "</b><br>"
            Response.Write "By "
            
            '// Loop through each author
            For Each i In arrDetails.selectSingleNode ("Authors").ChildNodes
                  Response.Write i.Text & ", "
            Next
      End If
      
      '// Unload XML parser
      Set xmlDoc = Nothing
Else
      Response.Write "An error occurred. Sorry"
End If

'// Destroy the object
Set xmlHTTP = Nothing

'// Generic function to check whether something is empty or not
Function IsBlank(byref TempVar)
      Dim tmpType
      IsBlank = False

      select Case VarType(TempVar)
      
            'Empty & Null
            case 0,1
                  IsBlank = true
            
            'Strings
            case 8
                  if Len(TempVar) = 0 Then
                        IsBlank = True
                  end If
            
            'Object
            case 9
                  tmpType = TypeName(TempVar)
                  If (tmpType = "Nothing") Or (tmpType = "Empty") Then
                        IsBlank = True
                  End If
            
            'Arrays
            case 8192, 8204, 8209
                  'does it have any dimensions?
                  if UBound(TempVar) = -1 Then
                        IsBlank = True
                  end If

            'Anything else            
            case Else
                  IsBlank = False
      end Select
End Function
%>

-----------------------end code--------------------------

strAsin is the thing i am working on. I have a .txt file full of asin numbers. the goal of the script is to read that .txt file, query each number, and output the results to my text file.
The text file get written to fine, and the script as a whole works fine as it is now, but the asin is hard coded. I need to figure out a way to make it read the list, and do each number, then write the results. if anyone can help, please do :D thanks

-Shane
0
Comment
Question by:bugnuker
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 7

Accepted Solution

by:
j2nku earned 2000 total points
ID: 11815574
<%@ LANGUAGE="VBSCRIPT" %>
<% Option Explicit
Dim aID, devToken, xmlURL, strASIN, strType, xmlHTTP, xmlDoc, arrDetails, i
Dim xmlResponse
Dim FSO
Dim myFile, asinfile
set FSO = Server.CreateObject("scripting.FileSystemObject")
set myFile = fso.CreateTextFile("G:\test.txt", true)
set asinfile = fso.OpenTextFile("G:\somedir\myASINs.txt") ' you wrote you have a txt file full of numbers - write the path to it here

' == You didn't write how the ASIN numbers are written in the file.
' == I'll write 2 examples:

' // Ex. 1 - if the numbers are separated by space, comma, etc - no linebreaks

asins = Split(asinfile.readall," ") ' == Here i assume that numbers are separated with one blank space
For Each asinnumber in asins
  if isnumeric(trim(asinnumber)) then GetProdInfo trim(asinnumber)
next

' // Ex. 2 - if each line has one number

Do While Not asinfile.atEndOfStream
  asinnumber = trim(asinfile.readline)
  if isnumeric(asinnumber) Then GetProdInfo asinnumber
loop

Set asinfile = nothing

Function GetProdInfo(ASIN)

'// Your Amazon Associates' ID
aID = "aspit-20"

'// Your Developers Token
devToken = "none"

'// The ASIN of the product
strASIN = ASIN

'// The type of search (lite|heavy)
strType = "lite"

'// XML URL
xmlURL = "http://xml.amazon.com/onca/xml3" & _
"?t=" & aID & _
"&dev-t=" & devToken & _
"&AsinSearch=" & strASIN & _
"&type=" & strType & _
"&f=xml"

'// Create the XMLHTTP object
Set xmlHTTP = Server.CreateObject("MSXML2.ServerXMLHTTP")

'// Fire off the request!
xmlHTTP.Open "GET", xmlURL, False
xmlHTTP.Send

'// Check if everything's okay
If xmlHTTP.Status = 200 Then
     xmlResponse = xmlHTTP.ResponseXML.xml

     '// Load the XML parser
     Set xmlDoc = Server.CreateObject("Microsoft.XMLDOM")
     xmlDoc.Async = False
     xmlDoc.loadXML (xmlResponse)
     
     '// Check for error message
     If IsBlank(xmlDoc.selectSingleNode("//ErrorMsg")) = False Then
          Response.Write "An error occurred. Sorry"
     Else
          '// Set the Details node
          Set arrDetails = xmlDoc.selectSingleNode ("//Details")
         
          '// Show product details
                  myFile.WriteLine( arrDetails.SelectSingleNode ("Asin").Text )  & vbtab & ( arrDetails.SelectSingleNode

("ProductName").Text ) & vbtab & ( arrDetails.SelectSingleNode ("ListPrice").Text ) & vbtab & ( arrDetails.SelectSingleNode

("OurPrice").Text ) & vbtab & ( arrDetails.SelectSingleNode ("UsedPrice").Text )


                  myFile.WriteLine( arrDetails.SelectSingleNode ("Asin").Text )


          Response.Write "<b>" & arrDetails.selectSingleNode ("ProductName").Text & "</b><br>"
          Response.Write "By "
         
          '// Loop through each author
          For Each i In arrDetails.selectSingleNode ("Authors").ChildNodes
               Response.Write i.Text & ", "
          Next
     End If
     
     '// Unload XML parser
     Set xmlDoc = Nothing
Else
     Response.Write "An error occurred. Sorry"
End If

'// Destroy the object
Set xmlHTTP = Nothing

End Function

'// Generic function to check whether something is empty or not
Function IsBlank(byref TempVar)
     Dim tmpType
     IsBlank = False

     select Case VarType(TempVar)
     
          'Empty & Null
          case 0,1
               IsBlank = true
         
          'Strings
          case 8
               if Len(TempVar) = 0 Then
                    IsBlank = True
               end If
         
          'Object
          case 9
               tmpType = TypeName(TempVar)
               If (tmpType = "Nothing") Or (tmpType = "Empty") Then
                    IsBlank = True
               End If
         
          'Arrays
          case 8192, 8204, 8209
               'does it have any dimensions?
               if UBound(TempVar) = -1 Then
                    IsBlank = True
               end If

          'Anything else          
          case Else
               IsBlank = False
     end Select
End Function
%>

'---------------------- good luck!
0
 
LVL 8

Expert Comment

by:fozylet
ID: 12723551
thanks bugnuker, your gesture is appreciated.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question