Updating a Google Site Listpage/Listitem


Here is a quick and dirty (by fully functional) sample of updating a listpage/listitem in Google Sites using the Data API.

#!/usr/bin/python

import getpass
import gdata.sites.client
import gdata.sites.data

USER = 'test@example.com'
SITE = 'YOUR_SITE_NAME'
DOMAIN = 'YOUR_DOMAIN'  # or 'site' if you're not using a Google Apps domain.

# Setup our client.
client = gdata.sites.client.SitesClient(source='google-SitesListeItemUpdateTest', site=SITE, domain=DOMAIN)
client.ClientLogin(USER, getpass.getpass(), client.source)
client.ssl = True
client.http_client.debug = False

# Only fetch listpages.
feed = client.GetContentFeed(uri=client.MakeContentFeedUri() + '?kind=listpage')

# Work with first listpage we found.
lp = feed.GetListPages()[0]

print 'Listpage columns:'
for col in lp.data.column:
  print 'index: %s, name: %s' % (col.index, col.name)

# Query the listpage's listems and work with first row found.
li = client.GetContentFeed(uri=lp.feed_link.href).entry[0]

print 'Row contents:'
for field in li.field:
  print 'index: %s, name: %s, value: %s' % (field.index, field.name, field.text)

# Update the first fields/column's value.
li.field[0].text = 'Someone else'
entry = client.Update(li)

# Update the listpage's column heading.
#lp.data.column[0].name = 'New Heading'
#entry2 = client.Update(lp)

105 comments: