File: google.ml

package info (click to toggle)
perl4caml 0.9.5-8
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 540 kB
  • sloc: ml: 1,572; ansic: 957; makefile: 186; perl: 45
file content (34 lines) | stat: -rw-r--r-- 897 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
(* Example program which uses Net::Google to query Google.
 * You will need to have a Google API key in ~/.googlekey for this to work.
 * Copyright (C) 2003 Merjis Ltd.
 * $Id: google.ml,v 1.4 2003/12/11 17:41:52 rich Exp $
 *)

open Printf

open Pl_Net_Google

let () =
  (* Load Google API key. *)
  let home = Sys.getenv "HOME" in
  let chan = open_in (home ^ "/.googlekey") in
  let key = input_line chan in
  close_in chan;

  (* Create the Google query object. *)
  let google = Pl_Net_Google.new_ ~key () in

  (* Search. *)
  let search = google#search () in
  search#set_query "merjis";
  search#set_max_results 5;

  printf "Top 5 results for \"merjis\":\n"; flush stdout;

  List.iter
    (fun response ->
       printf "* %s\n  <URL:%s>\n\n" response#title response#url
    ) search#results;

  (* Perform a full collection - good way to find GC/allocation bugs. *)
  Gc.full_major ()