Skip to main content
コメントを頂いたので修正。
ソース リンク
ohga
  • 941
  • 5
  • 5

URL を生成するネタの LIST_PATH&db=%s&de=%s を追加(コメントを頂いたので修正)

LIST_PATH で取得て、DoDownload と、そこから呼ばれる _GetDownloadList の引数に start_date,たデータ( sites_json end_date を増やして、引き回して 期間指定のパラメータ付き)の URL を生成範囲指定を設定する。あとは既存の処理へ。。

URL を生成するネタの LIST_PATH&db=%s&de=%s を追加して、DoDownload と、そこから呼ばれる _GetDownloadList の引数に start_date, end_date を増やして、引き回して 期間指定のパラメータ付きの URL を生成、あとは既存の処理へ。。

diff -Nurb -i --strip-trailing-cr -Nur a/downloader.py b/downloader.py
--- a/downloader.py 1979-12-31 00:00:00.000000000 +0900
+++ b/downloader.py 2015-01-078 128:526:519.000000000 +0900
@@ -37,7 +37,7 @@
   """
   HOST = 'www.google.com'
   APP_NAME = 'Google-WMTdownloadscript-0.1'
-  LIST_PATH = '/webmasters/tools/downloads-list?hl=%s&siteUrl=%s'
+  LIST_PATH = '/webmasters/tools/downloads-list?hl=%s&siteUrl=%s&db=%s&de=%s'
   FILE_NAME_HEADER = 'content-disposition'
   TEXT_BEFORE_NAME = 'attachment; filename='
 
@@ -72,7 +72,7 @@
 
     self._logged_in = True
 
-  def DoDownload(self, site, tables_to_download):
+  def DoDownload(self, site, tables_to_download, start_date, end_date):
     """Download CSV files and write them to disk.
 
     Downloader must be logged in before this method can be called, otherwise
@@ -8893,76 +8893,7 @@
     if not self.IsLoggedIn():
       raise ValueError('Client not logged in.')
 
-    available = self._GetDownloadList(site)
+    available = self._GetDownloadList(site, start_date, end_date)
     sites_json = json.loads(available)
 
     for key in tables_to_download:
@@ -111,7 +111,7 @@
   def SetLanguage(self, language_code):
     self._languageurl = language_code
 
-  def _GetDownloadList(self, site):
+  def _GetDownloadListsites_json.get(self, site, start_date, end_datekey):
     """Query the server for list of download URLs.
 
     Args:
@@ -123,7 +123,7 @@
 
       {'TOP_QUERIES':'webmaster/tools/top-search-queries-dl?...'}
     """
-    url = self._GetFullUrl(self.LIST_PATH % (self._language,url site))
+    url'&db=' =+ selfstart_date._GetFullUrlstrftime(self.LIST_PATH %"%Y%m%d") (self._language,+ site,'&de=' start_date,+ end_date).strftime("%Y%m%d")
     res_stream = self._client.request('GET',if url):
     download_list = res_stream.read()
     res_streamself.close_DownloadFile(url)

URL を生成するネタの LIST_PATH&db=%s&de=%s を追加て、DoDownload と、そこから呼ばれる _GetDownloadList の引数に start_date, end_date を増やして、引き回して 期間指定のパラメータ付きの URL を生成、あとは既存の処理へ。。

diff -Nurb -i --strip-trailing-cr -Nur a/downloader.py b/downloader.py
--- a/downloader.py 1979-12-31 00:00:00.000000000 +0900
+++ b/downloader.py 2015-01-07 12:56:19.000000000 +0900
@@ -37,7 +37,7 @@
   """
   HOST = 'www.google.com'
   APP_NAME = 'Google-WMTdownloadscript-0.1'
-  LIST_PATH = '/webmasters/tools/downloads-list?hl=%s&siteUrl=%s'
+  LIST_PATH = '/webmasters/tools/downloads-list?hl=%s&siteUrl=%s&db=%s&de=%s'
   FILE_NAME_HEADER = 'content-disposition'
   TEXT_BEFORE_NAME = 'attachment; filename='
 
@@ -72,7 +72,7 @@
 
     self._logged_in = True
 
-  def DoDownload(self, site, tables_to_download):
+  def DoDownload(self, site, tables_to_download, start_date, end_date):
     """Download CSV files and write them to disk.
 
     Downloader must be logged in before this method can be called, otherwise
@@ -88,7 +88,7 @@
     if not self.IsLoggedIn():
       raise ValueError('Client not logged in.')
 
-    available = self._GetDownloadList(site)
+    available = self._GetDownloadList(site, start_date, end_date)
     sites_json = json.loads(available)
 
     for key in tables_to_download:
@@ -111,7 +111,7 @@
   def SetLanguage(self, language_code):
     self._language = language_code
 
-  def _GetDownloadList(self, site):
+  def _GetDownloadList(self, site, start_date, end_date):
     """Query the server for list of download URLs.
 
     Args:
@@ -123,7 +123,7 @@
 
       {'TOP_QUERIES':'webmaster/tools/top-search-queries-dl?...'}
     """
-    url = self._GetFullUrl(self.LIST_PATH % (self._language, site))
+    url = self._GetFullUrl(self.LIST_PATH % (self._language, site, start_date, end_date))
     res_stream = self._client.request('GET', url)
     download_list = res_stream.read()
     res_stream.close()

(コメントを頂いたので修正)

LIST_PATH で取得たデータ( sites_json )の URL 範囲指定を設定する。あとは既存の処理へ。。

URL を生成するネタの LIST_PATH&db=%s&de=%s を追加して、DoDownload と、そこから呼ばれる _GetDownloadList の引数に start_date, end_date を増やして、引き回して 期間指定のパラメータ付きの URL を生成、あとは既存の処理へ。。

diff -Nurb -i --strip-trailing-cr a/downloader.py b/downloader.py
--- a/downloader.py 1979-12-31 00:00:00.000000000 +0900
+++ b/downloader.py 2015-01-08 18:26:51.000000000 +0900
@@ -72,7 +72,7 @@
 
     self._logged_in = True
 
-  def DoDownload(self, site, tables_to_download):
+  def DoDownload(self, site, tables_to_download, start_date, end_date):
     """Download CSV files and write them to disk.
 
     Downloader must be logged in before this method can be called, otherwise
@@ -93,6 +93,7 @@
 
     for key in tables_to_download:
       url = sites_json.get(key)
+      url = url + '&db=' + start_date.strftime("%Y%m%d") + '&de=' + end_date.strftime("%Y%m%d")
       if url:
         self._DownloadFile(url)
ソース リンク
ohga
  • 941
  • 5
  • 5

動作確認まではしてないので、ご参考程度に。。

まず、example-simple-download.pyDoDownload の 呼び出しで start_date, end_date を追加します。(範囲指定)

diff -Nurb -i --strip-trailing-cr -Nur a/example-simple-download.py b/example-simple-download.py
--- a/example-simple-download.py    1979-12-31 00:00:00.000000000 +0900
+++ b/example-simple-download.py    2015-01-07 12:55:22.000000000 +0900
@@ -23,6 +23,7 @@
 
 # Import the downloader
 from downloader import Downloader
+from datetime import date
 
 # Email address and password used to sign-in to Webmaster Tools
 email = '[email protected]'
@@ -31,9 +32,12 @@
 website = 'http://www.example.com/'
 selected_downloads = ['TOP_QUERIES']
 
+start_date = date(2014,12,1)
+end_date = date(2015,1,1)
+
 # Instantiate the downloader object
 downloader = Downloader()
 # Authenticate with your Webmaster Tools sign-in info
 downloader.LogIn(email, password)
 # Initiate the download
-downloader.DoDownload(website, selected_downloads)
+downloader.DoDownload(website, selected_downloads, start_date, end_date)

次に、downloader.py にて

URL を生成するネタの LIST_PATH&db=%s&de=%s を追加して、DoDownload と、そこから呼ばれる _GetDownloadList の引数に start_date, end_date を増やして、引き回して 期間指定のパラメータ付きの URL を生成、あとは既存の処理へ。。

diff -Nurb -i --strip-trailing-cr -Nur a/downloader.py b/downloader.py
--- a/downloader.py 1979-12-31 00:00:00.000000000 +0900
+++ b/downloader.py 2015-01-07 12:56:19.000000000 +0900
@@ -37,7 +37,7 @@
   """
   HOST = 'www.google.com'
   APP_NAME = 'Google-WMTdownloadscript-0.1'
-  LIST_PATH = '/webmasters/tools/downloads-list?hl=%s&siteUrl=%s'
+  LIST_PATH = '/webmasters/tools/downloads-list?hl=%s&siteUrl=%s&db=%s&de=%s'
   FILE_NAME_HEADER = 'content-disposition'
   TEXT_BEFORE_NAME = 'attachment; filename='
 
@@ -72,7 +72,7 @@
 
     self._logged_in = True
 
-  def DoDownload(self, site, tables_to_download):
+  def DoDownload(self, site, tables_to_download, start_date, end_date):
     """Download CSV files and write them to disk.
 
     Downloader must be logged in before this method can be called, otherwise
@@ -88,7 +88,7 @@
     if not self.IsLoggedIn():
       raise ValueError('Client not logged in.')
 
-    available = self._GetDownloadList(site)
+    available = self._GetDownloadList(site, start_date, end_date)
     sites_json = json.loads(available)
 
     for key in tables_to_download:
@@ -111,7 +111,7 @@
   def SetLanguage(self, language_code):
     self._language = language_code
 
-  def _GetDownloadList(self, site):
+  def _GetDownloadList(self, site, start_date, end_date):
     """Query the server for list of download URLs.
 
     Args:
@@ -123,7 +123,7 @@
 
       {'TOP_QUERIES':'webmaster/tools/top-search-queries-dl?...'}
     """
-    url = self._GetFullUrl(self.LIST_PATH % (self._language, site))
+    url = self._GetFullUrl(self.LIST_PATH % (self._language, site, start_date, end_date))
     res_stream = self._client.request('GET', url)
     download_list = res_stream.read()
     res_stream.close()