Exemplo n.º 1
0
    def AddSitemap(self,
                   site_uri,
                   sitemap_uri,
                   sitemap_type='WEB',
                   uri=SITEMAPS_FEED_TEMPLATE,
                   url_params=None,
                   escape_params=True,
                   converter=None):
        """Adds a regular sitemap to a site.

        Args:
          site_uri: str URI of which site to add sitemap for.
          sitemap_uri: str URI of sitemap to add to a site.
          sitemap_type: str Type of added sitemap. Valid types: WEB, VIDEO, or CODE.
          uri: str (optional) URI template to add a sitemap.
               Default SITEMAP_FEED_TEMPLATE.
          url_params: dict (optional) Additional URL parameters to be included
                      in the insertion request.
          escape_params: boolean (optional) If true, the url_parameters will be
                         escaped before they are included in the request.
          converter: func (optional) Function which is executed on the server's
              response before it is returned. Usually this is a function like
              SitemapsEntryFromString which will parse the response and turn it into
              an object.

        Returns:
          If converter is defined, the results of running converter on the server's
          response. Otherwise, it will be a SitemapsEntry object.
        """

        sitemap_entry = webmastertools.SitemapsEntry(
            atom_id=atom.Id(text=sitemap_uri),
            category=atom.Category(
                scheme='http://schemas.google.com/g/2005#kind',
                term=
                'http://schemas.google.com/webmasters/tools/2007#sitemap-regular'
            ),
            sitemap_type=webmastertools.SitemapType(text=sitemap_type))
        response = self.Post(sitemap_entry,
                             uri %
                             {'site_id': urllib.parse.quote_plus(site_uri)},
                             url_params=url_params,
                             escape_params=escape_params,
                             converter=converter)
        if not converter and isinstance(response, atom.Entry):
            return webmastertools.SitemapsEntryFromString(response.ToString())
        return response
 def testRegularToAndFromString(self):
     entry = webmastertools.SitemapsEntry(
         sitemap_type=webmastertools.SitemapType(text='WEB'),
         sitemap_status=webmastertools.SitemapStatus(text='Pending'),
         sitemap_last_downloaded=webmastertools.SitemapLastDownloaded(
             text='2006-11-18T19:27:32.543Z'),
         sitemap_url_count=webmastertools.SitemapUrlCount(text='102'),
     )
     self.assert_(entry.sitemap_type.text == 'WEB')
     self.assert_(entry.sitemap_status.text == 'Pending')
     self.assert_(entry.sitemap_last_downloaded.text ==\
         '2006-11-18T19:27:32.543Z')
     self.assert_(entry.sitemap_url_count.text == '102')
     new_entry = webmastertools.SitemapsEntryFromString(entry.ToString())
     self.assert_(new_entry.sitemap_type.text == 'WEB')
     self.assert_(new_entry.sitemap_status.text == 'Pending')
     self.assert_(new_entry.sitemap_last_downloaded.text ==\
         '2006-11-18T19:27:32.543Z')
     self.assert_(new_entry.sitemap_url_count.text == '102')
 def setUp(self):
     self.sitemap_type = webmastertools.SitemapType()