Check for specific price

Top  Previous  Next

The following example extracts a specified price from a certain page and only alerts an update if the price is lower than a predefined price. This price extraction is dependent from the page, you can use the code below as a starting point.


An alternative to such a plugin might be the regexcmp function that can be used in Ignore filters, Watch filters and the Keywords functionality.


Sub ExtractPrice(sMem, ByRef nPrice)


 Dim p, nLen


   nPrice = -1

   sMem = DeleteHtmlTags(sMem)

   ' Extract price without decimal places

   If FindRegex(sMem, "Price:\s*EUR\s*\d+,", p, nLen) Then

      sMem = ExtractDigits(Copy(sMem, p, nLen))

      nPrice = StrToIntDef(sMem, -1)

   End If

End Sub




Sub Wsw_CompareVersions(Handle, ByRef sMemWeb, ByRef sMemLocal, ByRef sStatusMessage, ByRef iStatusCode)


 Dim nPriceNew , nPriceOld, nPriceRef


   ' Define reference price (100 EUR)

   nPriceRef = 100


   ' Extract price from new/local version

   ExtractPrice(sMemWeb, nPriceNew)

   ExtractPrice(sMemLocal, nPriceOld) ' only needed to speed up several WSW routines


   ' Return only price - speed up several WSW routines, eg. "Test filter" dialog or "Analyze" functionality

   sMemWeb = IntToStr(nPriceNew)

   sMemLocal = IntToStr(nPriceOld)


   If nPriceNew = -Then

      iStatusCode = 2

      sStatusMessage = "Error extracting price"

   ElseIf (nPriceNew <> nPriceOld) And (nPriceNew <= nPriceRef) Then

      iStatusCode = 1

      sStatusMessage = "Price changed and lower than EUR " + IntToStr(nPriceNew)

   ElseIf (nPriceNew <> nPriceOld) And (nPriceNew > nPriceRef) Then

      iStatusCode = 0

      sStatusMessage = "Price too high"


      iStatusCode = 0

      sStatusMessage = "Price unchanged"

   End If

End Sub

Translate document: