[Mac] 使用 gsutil 查詢 Android Developer Console 的評論
目前在 Google Play 上有上架一個圖書館多重帳戶登入的 Android app,
偶爾會有人上去留言說遇到了什麼問題等等~
這些評論在 Google Play Developer Console 裡都可以看到,
只是奇怪的是 Google 並沒有設定成在有新評論的時候,就自動寄信給開發者,
因此常常是一陣子上去看的時候,才發現之前有人留言問問題了,
這時候再回覆就有點失去時效性…
看到 Developer console 在評論的那頁下面,
說可以用 gsutil 這個工具來抓評論,那就來試試看吧~
如果可以自動化每天看看有沒有新的評論,那就是最方便的了~
參考資料:
gsutil tool 這邊是 gsutil 這個工具的說明
Install gsutil 則是如何安裝 gsutil
1. 安裝 cffi 套件
網頁上是有另外一種使用 tar ball 安裝的方式,不過我懶,
所以選擇了 pip 的方式 (後來遇到的問題解的時間好像多到有點不太划算…)
首先照著網頁上的指令,直接執行 pip install gsutil,
很快就跳錯誤了,說 ffi.h 找不到…
在 python-cffi 的論壇上找到了解答,用下面的指令先將 cffi 裝好:
brew install pkg-config libffi export PKG_CONFIG_PATH=/usr/local/Cellar/libffi/3.0.13/lib/pkgconfig/ pip install cffi
2. 使用 pip 安裝 gsutil
cffi 裝好之後,就可以用 pip 安裝 gsutil:
pip install gsutil
裝一裝就又出現錯誤,說 libssl.1.0.0.dylib 找不到… (耐心消磨中)
gcc -bundle -undefined dynamic_lookup -L//anaconda/lib -arch x86_64 -arch x86_64 /private/var/folders/qg/l7_9f_4x707br0gghptzfs0cjr0hkh/T/pip_build_testuser/cryptography/cryptography/hazmat/bindings/__pycache__/cryptography/hazmat/bindings/__pycache__/_Cryptography_cffi_36a40ff0x2bad1bae.o -L//anaconda/lib -lssl -lcrypto -o /private/var/folders/qg/l7_9f_4x707br0gghptzfs0cjr0hkh/T/pip_build_testuser/cryptography/cryptography/hazmat/bindings/__pycache__/_Cryptography_cffi_36a40ff0x2bad1bae.so Traceback (most recent call last): File "<string>", line 1, in <module> File "/private/var/folders/qg/l7_9f_4x707br0gghptzfs0cjr0hkh/T/pip_build_testuser/cryptography/setup.py", line 338, in <module> **keywords_with_side_effects(sys.argv) File "//anaconda/lib/python2.7/distutils/core.py", line 152, in setup dist.run_commands() File "//anaconda/lib/python2.7/distutils/dist.py", line 953, in run_commands self.run_command(cmd) File "//anaconda/lib/python2.7/distutils/dist.py", line 971, in run_command cmd_obj.ensure_finalized() File "//anaconda/lib/python2.7/distutils/cmd.py", line 109, in ensure_finalized self.finalize_options() File "/private/var/folders/qg/l7_9f_4x707br0gghptzfs0cjr0hkh/T/pip_build_testuser/cryptography/setup.py", line 118, in finalize_options self.distribution.ext_modules = get_ext_modules() File "/private/var/folders/qg/l7_9f_4x707br0gghptzfs0cjr0hkh/T/pip_build_testuser/cryptography/setup.py", line 86, in get_ext_modules OpenSSLBinding().ffi.verifier.get_extension(), File "cryptography/hazmat/bindings/openssl/binding.py", line 89, in __init__ self._ensure_ffi_initialized() File "cryptography/hazmat/bindings/openssl/binding.py", line 113, in _ensure_ffi_initialized libraries=libraries, File "cryptography/hazmat/bindings/utils.py", line 80, in build_ffi extra_link_args=extra_link_args, File "//anaconda/lib/python2.7/site-packages/cffi/api.py", line 340, in verify lib = self.verifier.load_library() File "//anaconda/lib/python2.7/site-packages/cffi/verifier.py", line 75, in load_library return self._load_library() File "//anaconda/lib/python2.7/site-packages/cffi/verifier.py", line 151, in _load_library return self._vengine.load_library() File "//anaconda/lib/python2.7/site-packages/cffi/vengine_cpy.py", line 149, in load_library raise ffiplatform.VerificationError(error) cffi.ffiplatform.VerificationError: importing '/private/var/folders/qg/l7_9f_4x707br0gghptzfs0cjr0hkh/T/pip_build_testuser/cryptography/cryptography/hazmat/bindings/__pycache__/_Cryptography_cffi_36a40ff0x2bad1bae.so': dlopen(/private/var/folders/qg/l7_9f_4x707br0gghptzfs0cjr0hkh/T/pip_build_testuser/cryptography/cryptography/hazmat/bindings/__pycache__/_Cryptography_cffi_36a40ff0x2bad1bae.so, 2): Library not loaded: libssl.1.0.0.dylib
嗯… Library 沒 load 成功的話,在 Linux 上通常可以直接設定 LD_LIBRARY_PATH 試試,
不過在 Mac OS X 上要怎麼弄呢?
看了 Stackoverflow: Is it OK to use DYLD_LIBRARY_PATH on Mac OS X? 這篇的解答,
決定來設定一下 DYLD_FALLBACK_LIBRARY_PATH 這個環境變數,
先設成 Homebrew 下的 openssl 的路徑瞧瞧:
export DYLD_FALLBACK_LIBRARY_PATH=/usr//local/Cellar/openssl/1.0.1j/lib
嗯… 錯誤依舊… (瀕臨崩潰邊緣)
不遇錯誤訊息有點不一樣了,說 symbol 找不到,
表示它有讀到我們指定目錄下的 libssl.1.0.0.dylib,只是這版本的似乎有點不對頭:
cffi.ffiplatform.VerificationError: importing '/private/var/folders/qg/l7_9f_4x707br0gghptzfs0cjr0hkh/T/pip_build_testuser/cryptography/cryptography/hazmat/bindings/__pycache__/_Cryptography_cffi_36a40ff0x2bad1bae.so': dlopen(/private/var/folders/qg/l7_9f_4x707br0gghptzfs0cjr0hkh/T/pip_build_testuser/cryptography/cryptography/hazmat/bindings/__pycache__/_Cryptography_cffi_36a40ff0x2bad1bae.so, 2): Symbol not found: _SSLv2_client_method
觀察了一下,發現我給它的路徑是 openssl 1.0.1j 版的,
而它要的是 1.0.0 版,也許問題就出在這裡…
在 / 下搜尋了一下 libssl*, 在 /anaconda/lib 找到了一份 libssl.1.0.0.dylib,
就用它來試試看吧:
export DYLD_FALLBACK_LIBRARY_PATH=/anaconda/lib pip install gsutil
Bingo!這次成功將 gsutil 裝起來,總算沒有錯誤了…
3. 確認 gsutil 可以抓取公開資料
Google 網頁上有公開一個位址,可以讓 gsutil 確認可以抓到公開的資料,
先用來確認 gsutil 連線都沒有問題:
testuser@localhost ~ $ gsutil ls gs://uspto-pair/applications/0800401*
gs://uspto-pair/applications/08004010.zip
gs://uspto-pair/applications/08004011.zip
gs://uspto-pair/applications/08004012.zip
gs://uspto-pair/applications/08004013.zip
gs://uspto-pair/applications/08004016.zip
gs://uspto-pair/applications/08004017.zip
gs://uspto-pair/applications/08004019.zip
執行成功的話,應該會如上所示,列出一堆 zip 檔案~
4. 使用 gsutil 抓取評論時間
要抓取 Google Play Developer Console 上的評論資料,
照網頁上面說它是屬於非公開資料:
不過雖然是非公開資料,但是要列出檔案列表是沒有問題的,
用 ls -l 選項就可以將檔案時間也列出來,或是用 -L 列出更詳細的資料:
testuser@localhost ~ $ gsutil ls -l gs://pubsite_prod_rev_06884140820398223217/reviews 750 2014-07-05T20:22:22Z gs://pubsite_prod_rev_06884140820398223217/reviews/reviews_idv.ephrain.multilibrarylogin_201308.csv 363 2014-07-05T17:57:15Z gs://pubsite_prod_rev_06884140820398223217/reviews/reviews_idv.ephrain.multilibrarylogin_201309.csv 315 2014-07-05T13:44:25Z gs://pubsite_prod_rev_06884140820398223217/reviews/reviews_idv.ephrain.multilibrarylogin_201310.csv 646 2014-07-04T17:34:28Z gs://pubsite_prod_rev_06884140820398223217/reviews/reviews_idv.ephrain.multilibrarylogin_201311.csv 355 2014-07-04T15:28:32Z gs://pubsite_prod_rev_06884140820398223217/reviews/reviews_idv.ephrain.multilibrarylogin_201312.csv 455 2014-07-04T08:02:39Z gs://pubsite_prod_rev_06884140820398223217/reviews/reviews_idv.ephrain.multilibrarylogin_201401.csv 563 2014-06-27T19:07:21Z gs://pubsite_prod_rev_06884140820398223217/reviews/reviews_idv.ephrain.multilibrarylogin_201403.csv 368 2014-06-27T13:06:47Z gs://pubsite_prod_rev_06884140820398223217/reviews/reviews_idv.ephrain.multilibrarylogin_201404.csv 589 2014-06-27T00:37:54Z gs://pubsite_prod_rev_06884140820398223217/reviews/reviews_idv.ephrain.multilibrarylogin_201405.csv 367 2014-06-29T12:39:45Z gs://pubsite_prod_rev_06884140820398223217/reviews/reviews_idv.ephrain.multilibrarylogin_201406.csv 642 2014-11-18T00:33:00Z gs://pubsite_prod_rev_06884140820398223217/reviews/reviews_idv.ephrain.multilibrarylogin_201407.csv 1726 2014-11-18T00:33:00Z gs://pubsite_prod_rev_06884140820398223217/reviews/reviews_idv.ephrain.multilibrarylogin_201408.csv 874 2014-11-18T00:32:59Z gs://pubsite_prod_rev_06884140820398223217/reviews/reviews_idv.ephrain.multilibrarylogin_201409.csv 659 2014-11-15T18:45:20Z gs://pubsite_prod_rev_06884140820398223217/reviews/reviews_idv.ephrain.multilibrarylogin_201410.csv 924 2014-11-27T14:58:27Z gs://pubsite_prod_rev_06884140820398223217/reviews/reviews_idv.ephrain.multilibrarylogin_201411.csv TOTAL: 15 objects, 9596 bytes (9.37 KiB)
雖然目前這樣子是沒辦法讀到評論的內容,不過可以看到最後評論的時間,
這點對我來說已經足夠了,
我只需要每天自動執行 gsutil,看一下列表和前一天有無不同,
若是有改變的話再上去 Google Play Developer Console 看一下新的評論就行了~
關於用 gsutil 讀到非公開資料的內容的部分… 等有需要時再來研究吧 (懶) :P~