動作確認まではしてないので、ご参考程度に。。
まず、example-simple-download.py
の DoDownload
の 呼び出しで 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
にて
(コメントを頂いたので修正)
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)