home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / doc / python-gdata / examples / webmastertools / SitesFeedSummary.py < prev   
Encoding:
Python Source  |  2008-10-13  |  1.9 KB  |  71 lines

  1. #!/usr/bin/python
  2. #
  3. # Copyright (C) 2008 Yu-Jie Lin
  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.webmastertools.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 getpass
  26.  
  27.  
  28. username = ''
  29. password = ''
  30.  
  31. username = raw_input('Please enter your username: ')
  32. password = getpass.getpass()
  33.  
  34. client = gdata.webmastertools.service.GWebmasterToolsService(
  35.     email=username, 
  36.     password=password, source='PythonWebmasterToolsSample-1')
  37.  
  38. print 'Logging in'
  39. client.ProgrammaticLogin()
  40.  
  41. print 'Retrieving Sites feed'
  42. feed = client.GetSitesFeed()
  43.  
  44. # Format the feed
  45. print
  46. print 'You have %d site(s), last updated at %s' % (
  47.     len(feed.entry), feed.updated.text)
  48. print
  49. print "%-25s %25s %25s" % ('Site', 'Last Updated', 'Last Crawled')
  50. print '='*80
  51.  
  52.  
  53. def safeElementText(element):
  54.   if hasattr(element, 'text'):
  55.      return element.text
  56.   return ''
  57.  
  58.  
  59. # Format each site
  60. for entry in feed.entry:
  61.   print "%-25s %25s %25s" % (
  62.       entry.title.text.replace('http://', '')[:25], entry.updated.text[:25],
  63.       safeElementText(entry.crawled)[:25])
  64.   print "  Preferred: %-23s Indexed: %5s        GeoLoc: %10s" % (
  65.       safeElementText(entry.preferred_domain)[:30], entry.indexed.text[:5],
  66.       safeElementText(entry.geolocation)[:10])
  67.   print "  Crawl rate: %-10s            Verified: %5s" % (
  68.       safeElementText(entry.crawl_rate)[:10], entry.verified.text[:5])
  69.  
  70. print
  71.