Allow exporting items data in CSV format
まだ誰も着手していません。
評価
調査の方向性
scrapinghub/hubstorage/resourcetype.py の apirequest() と、scrapinghub/hubstorage/serialization.py の jldecode() 周辺から始め、format と fields がどのように Storage API に渡されるかを追跡します。完了条件は、クライアントが JSON のデコードエラーなしでフィールドを限定した CSV レスポンスを要求でき、JSON についても要求したフィールドが説明どおりに反映されることです。
索引モデルが issue の本文から書いたものです。
説明
I am using the client to request items but I would like to limit them because some of the fields are way too big. So I only need a few fields but I want all the items. For example, this works fine for CSV if I declare the fields parameter:
$ curl -uAPIKEY: "https://storage.scrapinghub.com/items/244066/83/3?format=csv&fields=name,venue"
"Ole Miss","Vaught Hemingway Stadium"
"Kansas State","Bill Snyder Family Stadium"
"LSU","Tiger Stadium"
But when I try it with the client I get:
Python 3.6.3 (default, Oct 3 2017, 21:45:48)
>>> import scrapinghub
>>> scrapinghub.__version__
'2.0.3'
>>> client = scrapinghub.ScrapinghubClient(APIKEY)
>>> job = client.get_job('244066/83/3')
>>> items = job.items.list(format='csv', fields=['name,venue'])
requests.exceptions.HTTPError: 406 Client Error: Not Acceptable for url:
https://storage.scrapinghub.com/items/244066/83/3?format=csv&fields=name%2Cvenue
scrapinghub.client.exceptions.ScrapinghubAPIError: No acceptable
content types matching header 'application/x-msgpack' and format 'csv'
The following are supported: application/x-msgpack, application/xml,
text/csv, application/json, application/x-jsonlines
Ok, so let's try without msgpack:
>>> client = scrapinghub.ScrapinghubClient(APIKEY, use_msgpack=False)
>>> job = client.get_job('244066/83/3')
>>> items = job.items.list(format='csv', fields=['name,venue'])
File "scrapinghub/hubstorage/serialization.py", line 25, in jldecode
yield loads(line)
json.decoder.JSONDecodeError: Extra data: line 1 column 11 (char 10)
So the problem is that the response is assumed by the client to be JSON and it tries to decode the string:
'"Ole Miss","Vaught Hemingway Stadium"'
Ok, let's try it with json now:
>>> items = job.items.list(format='json', fields=['name,venue'])
>>> items
[[{'name': 'Ole Miss', 'venue': 'Vaught Hemingway Stadium',
'venue_address': 'All-American Dr, University, MS 38677, EUA',
'date': 1542857400000.0,...
Well, there's no error, but we get all the fields instead of just the two we request, effectively the fields parameter is ignored.
So maybe we could patch scrapinghub/hubstorage/resourcetype.py:apirequest() to check for the csv format to bypass the json decoding but it would actually be better if the backend api supported this field subset declaration for other formats, namely json.
I see that the api supports max_fields and we know that csv supports field limiting so maybe it's not a big deal to get the api to support field limiting for json as well.
- 主要言語
- Python
- スター
- 204
- フォーク
- 62
- 平均マージ
- 6分
- マージ済み PR(30日)
- 2
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
scrapinghub/python-scrapinghub のほかの issue
-
Incorrect information for Samples in Job documentation対応中かも @AdrianAtZyte が 66 日前に担当しました。 オープン
難易度 1/5 1時間未満 初心者へのやさしさ 72/100
-
Zyte Job API: Provision to support Cron Expression or Time Interval対応中かも @AdrianAtZyte が 67 日前に担当しました。 オープン
難易度 5/5 1週間以上 初心者へのやさしさ 25/100
-
Add async support再び着手できるかも @VMRuiz が 1414 日前に担当しましたが、オープン中のプルリクエストはありません。 オープン
scrapinghub/python-scrapinghub#169 · コメント 8 件 · リアクション 2 件 · 担当者 4 名 ·
-
Add retry logic to Job Tag Update function対応中かも @AdrianAtZyte が 66 日前に担当しました。 オープン
難易度 3/5 1〜2日 初心者へのやさしさ 42/100
-
KeyError: 'status' when trying to schedule spider対応中かも @AdrianAtZyte が 64 日前に担当しました。 オープンenhancement
難易度 3/5 1〜2日 初心者へのやさしさ 30/100
scrapinghub/python-scrapinghub#156 · コメント 6 件 ·
scrapinghub/python-scrapinghub の issue をすべて見る
似ている issue
-
[19.0] pos_sale: settling an order with a 0 down payment line crashes (reading 'reward_id') and leaves a wrong amount due対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 79/100
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 79/100
developmentseed/titiler-covjson#164 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
awslabs/visual-asset-management-system#2164 ·
メンテナーはふだん 1 日以内に返信
-
needs-triage
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
MakazhanAlpamys/Soup#3589 ·
メンテナーはふだん 1 日以内に返信
-
channels status reports the wrong Enabled value for Feishu instances and default-enabled WebSocketオープン
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
メンテナーはふだん 1 日以内に返信