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


This function is called to compare the web version of a page with the locally saved version. You can filter the content and determine when a bookmark should report an update, for example when a specific price in the web version is lower than in the locally saved version. The parameter $iStatusCode is a numeric value that indicates whether a page has changed or an error has occurred.


Parameters


  • $sMemWeb ... String expression. Page source code of the web version.
  • $sMemLocal ... String expression. Page source code of the locally saved version.
  • $sStatusMessage ... String expression. Status message that is displayed in the status column. The default value is an empty string.
  • $iStatusCode ... Integer value. Indicates whether a page has changed or an error has occurred. The default value is 0.


Valid values of $iStatusCode


  • 0 ... OK, page is unchanged.
    Default value. Must not be assigned manually.
  • 1 ... OK, page has changed.
    Bookmark is marked as updated.
  • 2 ... Error.
    If 2 is returned, the bookmark check is aborted with an error.


Examples:


Simple example to check whether the filtered page content has changed.

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

   ' Apply the defined filter definitions
   $sMemWeb = Bookmark_ApplyFilter($sMemWeb)
   $sMemLocal = Bookmark_ApplyFilter($sMemLocal)

   ' Check if the page has been changed by comparing the filtered content
   If $sMemWeb <> $sMemLocal Then
      $iStatusCode = 1 ' updates detected
   Else
      $iStatusCode = 0 ' no updates available
   End If

End Sub



More advanced example to detect price changes and alert when a price is lower than a predefined value. The price extraction depends on the page structure. You can use the code below as a starting point.

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 = CInt($sMem)
   End If
End Sub

'*******************************************************************************

Sub Wsw_CompareVersions(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 = CStr($nPriceNew)
   $sMemLocal = CStr($nPriceOld)

   If $nPriceNew = -1 Then
      $iStatusCode = 2
      $sStatusMessage = "Error extracting price"
   ElseIf ($nPriceNew <> $nPriceOld) And ($nPriceNew <= $nPriceRef) Then
      $iStatusCode = 1
      $sStatusMessage = "Price changed and lower than EUR " + CStr($nPriceNew)
   ElseIf ($nPriceNew <> $nPriceOld) And ($nPriceNew > $nPriceRef) Then
      $iStatusCode = 0
      $sStatusMessage = "Price too high"
   Else
      $iStatusCode = 0
      $sStatusMessage = "Price unchanged"
   End If
End Sub