Archive for May, 2009

Writing a Private Plugin

Saturday, May 30th, 2009

This article shows how to use a Private Plugin to monitor a page for a specific price.

plugin05

The price in the red ellipsis is the price we want to monitor and WebSite-Watcher should only alert an update if this price is lowered against the locally saved version.

Launch the Plugin IDE

Open the bookmark properties, then select “Advanced” + “Plugin” + “Private Plugin” and click the button “Create Private Plugin”.

Create Private Plugin

This will open the Plugin IDE with the following tabs:

Private Plugins - Tabs

The “Plugin Script” tab is the section where you can enter the Plugin script (in “Basic” language). The other tabs are used to display the page source, the rendered page and the source code of other plugins.

To remember, a Plugin must contain one or more Event functions which are called from WebSite-Watcher at appropriate times. The Event function Wsw_CompareVersions is used to compare the web version of a page with the locally saved version, you can filter the content (in our case the price) and decide when an update notification should be made.

Extracting the price

In a first step, we have to implement a function that extracts the price from the page source. We use the following “Basic” code:

Function ExtractPrice(sMem) As Integer
 Dim p, nLen
   ExtractPrice = -1
   ' Skip "List Price:"
   If FindString(sMem, "List Price:", p, nLen) Then
      Delete(sMem, 1, p + nLen)
   End If
   ' Extract price
   If FindString(sMem, "Price:", p, nLen) Then
      Delete(sMem, 1, p)
      If FindRegex(sMem, "\$\d+\.\d+", p, nLen) Then
         sMem = ExtractDigits(Copy(sMem, p, nLen))
         ExtractPrice = CInt(sMem)
      End If
   End If
End Function

This function extracts all digits from the price and $8.99 becomes 899. This doesn’t matter for only comparing the price.

Comparing prices via the Event function

With “Insert + WSW Event functions” you can insert the function “Wsw_CompareVersions”. WebSite-Watcher calls this function with the source code of the web page and the source code of the locally saved version. The only thing we have to do is to extract the prices (with the function above), compare them and return the result of the comparison:

Sub Wsw_CompareVersions(Handle, ByRef sMemWeb, ByRef sMemLocal, ByRef sStatusMessage, ByRef iStatusCode)
 Dim nPriceNew, nPriceOld
   ' Extract prices
   nPriceNew = ExtractPrice(sMemWeb)
   nPriceOld = ExtractPrice(sMemLocal)
   ' Return only the price - this will speed up several WSW routines, eg. "Test filter" dialog
   '                         and makes testing easier
   sMemWeb = CStr(nPriceNew)
   sMemLocal = CStr(nPriceOld)
   If nPriceNew = -1 Then
      iStatusCode = 2
      sStatusMessage = "Error extracting price"
   ElseIf nPriceNew < nPriceOld Then
      iStatusCode = 1
      sStatusMessage = "Price lowered to EUR " + CStr(nPriceNew / 100)
   End If
End Sub

iStatusCode is an integer value and indicates if a page has been changed or if an error has occurred. Valid values are:

  • 0 … OK, page is unchanged. This is the default value and must not be assigned manually.
  • 1 … OK, page has been changed. The bookmark will be marked as updated.
  • 2 … Error. If 2 is returned, the check of that bookmark will be aborted with an error.

Assigning a text to sStatusMessage is optional and will be displayed in the status column of the bookmark list. The default value is an empty string.

Private Plugin IDE

After the script has been entered, click the OK button to return to the bookmark properties. From now on you will only get update notifications when the price is lowered.

Send opened page by e-mail

Tuesday, May 26th, 2009

A new feature in WebSite-Watcher 5.1.0 is to send the currently opened page by e-mail.

Send page by e-mail

You can either send the currently opened page as screenshot (PNG format) or as web page (ZIP format). The page will be sent with your default e-mail client using the MAPI interface. That means that your e-mail client has to support MAPI.

This feature is already available in WebSite-Watcher 5.1.0 Beta-4 and can be downloaded from the beta section.

The Plugin IDE

Friday, May 15th, 2009

This article shows the required IDE elements for creating Shared Plugins. After opening the Plugin IDE, you’ll see the following tabs:

Tabs in Plugin IDE

To create a Shared Plugin, you need the following three sections:

  1. Configuration
    In that section you have to enter the Plugin name, a description and if the Plugin should be suggested automatically for “compatible” pages.
  2. Identification
    For each Shared Plugin, concrete and unique identification strings of the HTML source code  must be entered. If all entered strings are available in the page, then the plugin is considered as compatible and a final (optional) test run of the plugin script shows if the page is fully compatible.
  3. Plugin Script
    Plugins are written in the programming language Basic. A script must contain one or more Event functions which are called from WebSite-Watcher at appropriate times. In the help file you can find a brief introduction of the supported “Basic” language features.

For creating Private Plugins, the first two tabs are not required (and hidden), you only have to implement the plugin script.

 

The Script Editor

The integrated Script Editor contains everything you need to create and debug plugins, no external tools or installations are required.

Script Editor

 

Editing Scripts

Here’s a small list of useful features when editing scripts:

  1. Pressing Ctrl+Enter opens the code completion list to quickly select and insert available functions. Enter for example “co” in the script editor and press Ctrl+Space, then you will see all functions that start with “co”.
  2. Moving the mouse over a function name displays the declaration of that function in a tooltip.
  3. Supported Event functions can be inserted via the “Insert” menu.
  4. Double clicking a function in the Code Explorer (left panel) jumps to the appropriate function in the source code.
  5. The source code can be formatted automatically with the shortcut Ctrl+L.
  6. Clicking onto a line number inserts/removes a breakpoint for debugging.

Debugging Scripts

The Plugin IDE contains full debugging capabilities for testing your scripts, here’s a small list of useful features:

  1. An Event function can be tested by pressing the F9 key (or the “Run” toolbar button). This will  open a window from where you can select the Event function you want to test. The bookmark configuration and page source of the selected bookmark are used as input.
  2. If the debugger stops at a breakpoint, you can use F7 (step into) or F8 (step over) to make execution steps in your script. F9 continues the script execution.
  3. Moving the mouse over a variable displays the value of that variable.
  4. Ctrl+F7 opens the Evaluation window to evaluate variables and expressions.

Private / Shared Plugins

Wednesday, May 13th, 2009

Starting with WebSite-Watcher 5.1.0 it’s possible to write plugins with the integrated Plugin IDE (integrated development environment).

WebSite-Watcher supports two type of Plugins:

  1. Private Plugins
    Private Plugins are created and stored per bookmark and cannot be shared between bookmarks. Use this plugin type if the plugin script is written individually for a specific page and you don’t need the same functionality for other bookmarks.
  2. Shared Plugins
    Shared Plugins are stored in separate files and can be shared between multiple bookmarks. Use this plugin type if you need it for multiple bookmarks.

A bookmark can have either a Private Plugin or a Shared Plugin, not both.

If you open “Advanced + Plugin” in the bookmark properties, you can see that this dialog has been changed a bit since WebSite-Watcher 5.0.

Create Plugins

Clicking the “Create Shared Plugin” or “Create Private Plugin” button will open the Plugin IDE that will be introduced in the next posts.

To quickly edit/change an existing Plugin from the bookmark list, you can use the context menu to launch the Plugin IDE (right click a bookmark + Extras + Plugin IDE).

Quickly open the Plugin IDE

WebSite-Watcher 5.1.0 Beta-1

Tuesday, May 12th, 2009

The first beta version of WebSite-Watcher 5.1.0 has been released and comes with three major changes, the first two of them required lots of code changes:

  1. Optimized and reduced memory usage, especially if you have lots of bookmarks with keywords or filter definitions.
  2. Unicode support in all program modules. As I wrote in a previous post, we moved to a new compiler version to get real Unicode support. In WebSite-Watcher this meant removing hundreds of “Unicode workarounds”, but as a result we got a much cleaner code and many other advantages in handling web pages. Due to that change, the minimum OS that is now required to run WebSite-Watcher is Windows 2000.
  3. A first version of the Plugin IDE (integrated development environment). The Plugin system was introduced in WebSite-Watcher 5.0, but it was only possible to use predefined Plugins that came with WebSite-Watcher. With that Plugin IDE, users can now write their own plugins. In the next few days I’ll make some posts about this Plugin system.

Open the Beta section to see a list of all changes and to download this new beta version.