cvsimport
[beagle.git] / wrappers / python / beaglesearch.py
blob88f4c335bbb19387f4cb0d3b255c2d6cd0cc565c
1 #!/usr/bin/env python
3 import beagle
4 import gobject
5 import sys
7 total_hits = 0
9 def hits_added_cb (query, response):
10 global total_hits
11 hits = response.get_hits()
12 num_matches = response.get_num_matches()
14 total_hits = total_hits + len(hits)
15 print "Returned hits (%d) out of total %d matches:" % (len(hits), num_matches)
16 print "-------------------------------------------"
18 for hit in hits:
19 if hit.get_type() == "FeedItem":
20 text = hit ['dc:title']
21 print "Blog: %s" % text
22 elif hit.get_type() == "File":
23 print "File: %s" % hit.get_uri()
24 elif hit.get_type() == "MailMessage":
25 print "Email: %s" % hit ['dc:title']
26 for sender in hit.get_properties ('fixme:from'):
27 print "\tSent by: %s" % sender
28 else:
29 print "%s (%s)" % (hit.get_uri(), hit.get_source())
31 print "-------------------------------------------"
33 def finished_cb (query, response, loop):
34 main_loop.quit()
36 client = beagle.Client()
37 main_loop = gobject.MainLoop()
38 query = beagle.Query()
40 for i in sys.argv[1:]:
41 query.add_text(i)
43 query.connect("hits-added", hits_added_cb)
44 query.connect("finished", finished_cb, main_loop)
45 client.send_request_async(query)
47 main_loop.run()
49 print "Found a total of %d hits" % total_hits