1 Values
2 Graphics


 (require (planet jeeve/live))
This basic library provided client web service and graphics to follow specifical values in web pages.

1 Values

(live-web-number url    
  delta-nb-lines])  number?
  url : string?
  key-line : string?
  regexp-pattern : string?
  error-value : number? = 0
  delta-nb-lines : number? = 0

Extracts a value in a web page.

Returns error-value if value not found or internet connection failed.

Example to get wind velocity on a spot location (via winds-up web page)

  • Open the web site

  • Inspect HTML code

To find appropriate parameters, visualize position of searched value. Search a word to locate a reference line (key-line parameter). In the example, we choose "Aujourd" for the key-line word with delta-nb-lines = 3 to jump to velocity wind value. The value is an integer, therefore regexp-pattern parameter is "[0-9]+".

Which gives

> (live-web-number "http://www.winds-up.com/index.php?p=spots&id=21"

Returns wind velocity read as an integer on winds-up web site at 3 lines after that containing "Aujourd" word. Otherwise returns -1.

Another examples:

Wind velocity at Belle-Ile, France via meteociel web site

> (live-web-number "http://www.meteociel.fr/observations-meteo/vent.php"
        "[0-9]+ km/h")

Water level web service

(define (water-level id-station)
  (lambda ()
    (live-web-number (string-append "http://www.vigicrues.gouv.fr/niveau3.php?idstation="
                                    (number->string id-station)

2 Graphics

(live-graph label function rate title)  any/c
  label : string?
  function : (-> number?)
  rate : number?
  title : string?

Graphic evolution of value in web page.

An example to display water level at Cavaillon in France (id-station = 142)

> (live-graph "Water level (m)"
   (water-level 142)
   (* 5 60) ; refresh each 5 minutes

An other example to obtain pressure level in Paris

(define (pressure-paris)
  (live-web-number "http://www.station-meteo.com/historique-fr75020-paris/"
                   "<td>Pression atmosphérique"

With axis scale parameterize

(parameterize ([delta-x (* 12 3600)] ; 12 hours
               [delta-y 0.01])  ; 1 %
  (live-graph "Level pressure (hPa)"
              (* 5 60)

Use live-dashboard function to plot multiple web services

(live-dashboard labels functions rate title)  any/c
  labels : (listof (listof string?))
  functions : (listof (listof (-> number?)))
  rate : number?
  title : string?

This function displays graphics in rows and columns disposition. Each sublist is a row.

> (live-dashboard '(("Ners" "Besseges"))
       (list (list (water-level 38) (water-level 31)))
       (* 5 60)
       "Water level (m)")

The same but with one function of label parameter

(live-dashboard-one-ft labels    
  title)  any/c
  labels : (listof (listof string?))
  function : (-> string? number?)
  rate : number?
  title : string?


> (live-dashboard-one-ft '(("Paris" "Marseille"))
              (* 15 60)
              "Pressure level (hPa)")

(pressure "Paris") and (pressure "Marseille") will be called every 15 minutes.