Exemplo n.º 1
0
    def AddNewsSitemap(self,
                       site_uri,
                       sitemap_uri,
                       sitemap_news_publication_label,
                       uri=SITEMAPS_FEED_TEMPLATE,
                       url_params=None,
                       escape_params=True,
                       converter=None):
        """Adds a news 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_news_publication_label: str, list of str Publication Labels for
                                          sitemap.
          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-news'
            ),
            sitemap_news_publication_label=[],
        )
        if isinstance(sitemap_news_publication_label, str):
            sitemap_news_publication_label = [sitemap_news_publication_label]
        for label in sitemap_news_publication_label:
            sitemap_entry.sitemap_news_publication_label.append(
                webmastertools.SitemapNewsPublicationLabel(text=label))
        print(sitemap_entry)
        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
Exemplo n.º 2
0
    def AddMobileSitemap(self,
                         site_uri,
                         sitemap_uri,
                         sitemap_mobile_markup_language='XHTML',
                         uri=SITEMAPS_FEED_TEMPLATE,
                         url_params=None,
                         escape_params=True,
                         converter=None):
        """Adds a mobile 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_mobile_markup_language: str Format of added sitemap. Valid types:
                                          XHTML, WML, or cHTML.
          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.
        """
        # FIXME
        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-mobile'),
            sitemap_mobile_markup_language= \
                webmastertools.SitemapMobileMarkupLanguage(
                    text=sitemap_mobile_markup_language))
        print(sitemap_entry)
        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')