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 / dryRunInsert.py < prev   
Encoding:
Python Source  |  2007-12-14  |  2.1 KB  |  61 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. import getpass
  27.  
  28. # Demonstrates item insertion with a dry run insert operation. The item will
  29. # NOT be added to Google Base.
  30.  
  31. gb_client = gdata.base.service.GBaseService()
  32. gb_client.email = raw_input('Please enter your username: ')
  33. gb_client.password = getpass.getpass()
  34.  
  35. print 'Logging in'
  36. gb_client.ProgrammaticLogin()
  37.  
  38. # Create a test item which will be used in a dry run insert
  39. item = gdata.base.GBaseItem()
  40. item.author.append(atom.Author(name=atom.Name(text='Mr. Smith')))
  41. item.title = atom.Title(text='He Jingxian\'s chicken')
  42. item.link.append(atom.Link(rel='alternate', link_type='text/html',
  43.     href='http://www.host.com/123456jsh9'))
  44. item.label.append(gdata.base.Label(text='kung pao chicken'))
  45. item.label.append(gdata.base.Label(text='chinese cuisine'))
  46. item.label.append(gdata.base.Label(text='testrecipes'))
  47. item.item_type = gdata.base.ItemType(text='recipes')
  48. item.AddItemAttribute(name='cooking_time', value_type='intUnit', value='30 minutes')
  49. item.AddItemAttribute(name='main_ingredient', value='chicken')
  50. item.AddItemAttribute(name='main_ingredient', value='chili')
  51.  
  52. # Make an insert request with the dry run flag set so that the item will not
  53. # actually be created.
  54. result = gb_client.InsertItem(item, url_params={'dry-run': 'true'})
  55.  
  56. # Send the XML from the server to standard out.
  57. print 'Here\'s the XML from the server\'s simulated insert'
  58. print str(result)
  59.  
  60. print 'Done'
  61.