47bd8e4341336b6f629000e4a547a8df99e815c0
[perl4caml.git] / examples / google.ml
1 (* Example program which uses Net::Google to query Google.
2  * You will need to have a Google API key in ~/.googlekey for this to work.
3  * Copyright (C) 2003 Merjis Ltd.
4  * $Id: google.ml,v 1.1 2003-10-14 16:05:21 rich Exp $
5  *)
6
7 open Printf
8
9 open Pl_Net_Google
10
11 let () =
12   (* This is a hack which shouldn't be needed in future. *)
13   Perl.eval "use Net::Google";
14
15   (* Load Google API key. *)
16   let home = Sys.getenv "HOME" in
17   let chan = open_in (home ^ "/.googlekey") in
18   let key = input_line chan in
19   close_in chan;
20
21   (* Create the Google query object. *)
22   let google = Pl_Net_Google.new_ ~key () in
23
24   (* Search. *)
25   let search = google#search () in
26   search#set_query "merjis";
27   search#set_max_results 5;
28
29   printf "Top 5 results for \"merjis\":\n"; flush stdout;
30
31   List.iter
32     (fun response ->
33        printf "* %s\n  <URL:%s>\n\n" response#title response#url
34     ) search#results;