Allow exporting items data in CSV format
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 35/100
Hướng nghiên cứu
Bắt đầu với scrapinghub/hubstorage/resourcetype.py tại apirequest() và scrapinghub/hubstorage/serialization.py xung quanh jldecode(), sau đó theo dõi cách format và fields được truyền đến Storage API. Hoàn tất nghĩa là client có thể yêu cầu phản hồi CSV chỉ gồm các field được giới hạn mà không gặp lỗi giải mã JSON, đồng thời các field được yêu cầu được tuân thủ đối với JSON như mô tả.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- Python
- Star
- 204
- Fork
- 62
- Merge trung bình
- 6 phút
- Pull request đã merge (30 ngày)
- 2
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của scrapinghub/python-scrapinghub
-
Incorrect information for Samples in Job documentationCó thể đã có người làm @AdrianAtZyte đã nhận 66 ngày trước. Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 72/100
-
Zyte Job API: Provision to support Cron Expression or Time IntervalCó thể đã có người làm @AdrianAtZyte đã nhận 67 ngày trước. Đang mở
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
-
Add async supportCó thể làm lại được @VMRuiz đã nhận 1414 ngày trước và không có pull request nào đang mở. Đang mở
scrapinghub/python-scrapinghub#169 · 8 bình luận · 2 reaction · 4 người được giao ·
-
Add retry logic to Job Tag Update functionCó thể đã có người làm @AdrianAtZyte đã nhận 66 ngày trước. Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 42/100
-
KeyError: 'status' when trying to schedule spiderCó thể đã có người làm @AdrianAtZyte đã nhận 64 ngày trước. Đang mởenhancement
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 30/100
scrapinghub/python-scrapinghub#156 · 6 bình luận ·
Tất cả issue của scrapinghub/python-scrapinghub
Issue tương tự
-
[19.0] pos_sale: settling an order with a 0 down payment line crashes (reading 'reward_id') and leaves a wrong amount dueCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 79/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 79/100
developmentseed/titiler-covjson#164 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
awslabs/visual-asset-management-system#2164 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
needs-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
MakazhanAlpamys/Soup#3589 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
channels status reports the wrong Enabled value for Feishu instances and default-enabled WebSocketĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
Maintainer thường phản hồi trong vòng 1 ngày