home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / doc / python-gdata / examples / base / baseQueryExample.py next >
Encoding:
Python Source  |  2007-05-04  |  1.6 KB  |  52 lines

  1. #!/usr/bin/python
  2. #
  3. # Copyright (C) 2007 Google Inc.
  4. #
  5. # Licensed under the Apache License, Version 2.0 (the "License");
  6. # you may not use this file except in compliance with the License.
  7. # You may obtain a copy of the License at
  8. #
  9. #      http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16.  
  17.  
  18. import gdata.base.service
  19. import gdata.service
  20. try:
  21.   from xml.etree import ElementTree
  22. except ImportError:
  23.   from elementtree import ElementTree
  24. import atom
  25. import gdata.base
  26.  
  27. # Demonstrates queries to the snippets feed and stepping through the results.
  28.  
  29. gb_client = gdata.base.service.GBaseService()
  30. q = gdata.base.service.BaseQuery()
  31. q.feed = '/base/feeds/snippets'
  32. q['start-index'] = '1'
  33. q['max-results'] = '10'
  34. q.bq = raw_input('Please enter your Google Base query: ')
  35.  
  36. feed = gb_client.QuerySnippetsFeed(q.ToUri())
  37.  
  38. while(int(q['start-index']) < 989):
  39.   # Display the titles of the snippets.
  40.   print 'Snippet query results items %s to %s' % (q['start-index'], 
  41.       int(q['start-index'])+10)
  42.   for entry in feed.entry:
  43.     print '  ', entry.title.text
  44.  
  45.   # Show the next 10 results from the snippets feed when the user presses 
  46.   # enter.
  47.   nothing = raw_input('Press enter to see the next 10 results')
  48.   q['start-index'] = str(int(q['start-index']) + 10)
  49.   feed = gb_client.QuerySnippetsFeed(q.ToUri())
  50.  
  51. print 'You\'ve reached the upper limit of 1000 items. Goodbye :)'
  52.