Skip to content

Commit 84895ce

Browse files
author
Rebecca Ysteboe
committed
Update API to 1.5.6
1 parent 0242647 commit 84895ce

File tree

5 files changed

+132
-10
lines changed

5 files changed

+132
-10
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
Changelog
22
====
33

4+
#### 1.5.6
5+
Release date: 9/19/19
6+
* Downloading all files for a competition downloads a zip instead of individual files
7+
48
#### 1.5.5
59
Release date: 8/30/19
610
* Add vote count and usability rating to datasets listing

KaggleSwagger.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,27 @@ paths:
282282
description: Error
283283
schema:
284284
$ref: '#/definitions/Error'
285+
/competitions/data/download-all/{id}:
286+
get:
287+
tags:
288+
- kaggle
289+
summary: Download all competition data files
290+
operationId: CompetitionsDataDownloadFiles
291+
parameters:
292+
- in: path
293+
name: id
294+
required: true
295+
type: string
296+
description: Competition name
297+
responses:
298+
200:
299+
description: Result
300+
schema:
301+
$ref: '#/definitions/Result'
302+
default:
303+
description: Error
304+
schema:
305+
$ref: '#/definitions/Error'
285306
/competitions/{id}/leaderboard/download:
286307
get:
287308
tags:

kaggle/api/kaggle_api.py

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,95 @@ def competitions_data_download_file_with_http_info(self, id, file_name, **kwargs
324324
_request_timeout=params.get('_request_timeout'),
325325
collection_formats=collection_formats)
326326

327+
def competitions_data_download_files(self, id, **kwargs): # noqa: E501
328+
"""Download all competition data files # noqa: E501
329+
330+
This method makes a synchronous HTTP request by default. To make an
331+
asynchronous HTTP request, please pass async_req=True
332+
>>> thread = api.competitions_data_download_files(id, async_req=True)
333+
>>> result = thread.get()
334+
335+
:param async_req bool
336+
:param str id: Competition name (required)
337+
:return: Result
338+
If the method is called asynchronously,
339+
returns the request thread.
340+
"""
341+
kwargs['_return_http_data_only'] = True
342+
if kwargs.get('async_req'):
343+
return self.competitions_data_download_files_with_http_info(id, **kwargs) # noqa: E501
344+
else:
345+
(data) = self.competitions_data_download_files_with_http_info(id, **kwargs) # noqa: E501
346+
return data
347+
348+
def competitions_data_download_files_with_http_info(self, id, **kwargs): # noqa: E501
349+
"""Download all competition data files # noqa: E501
350+
351+
This method makes a synchronous HTTP request by default. To make an
352+
asynchronous HTTP request, please pass async_req=True
353+
>>> thread = api.competitions_data_download_files_with_http_info(id, async_req=True)
354+
>>> result = thread.get()
355+
356+
:param async_req bool
357+
:param str id: Competition name (required)
358+
:return: Result
359+
If the method is called asynchronously,
360+
returns the request thread.
361+
"""
362+
363+
all_params = ['id'] # noqa: E501
364+
all_params.append('async_req')
365+
all_params.append('_return_http_data_only')
366+
all_params.append('_preload_content')
367+
all_params.append('_request_timeout')
368+
369+
params = locals()
370+
for key, val in six.iteritems(params['kwargs']):
371+
if key not in all_params:
372+
raise TypeError(
373+
"Got an unexpected keyword argument '%s'"
374+
" to method competitions_data_download_files" % key
375+
)
376+
params[key] = val
377+
del params['kwargs']
378+
# verify the required parameter 'id' is set
379+
if ('id' not in params or
380+
params['id'] is None):
381+
raise ValueError("Missing the required parameter `id` when calling `competitions_data_download_files`") # noqa: E501
382+
383+
collection_formats = {}
384+
385+
path_params = {}
386+
if 'id' in params:
387+
path_params['id'] = params['id'] # noqa: E501
388+
389+
query_params = []
390+
391+
header_params = {}
392+
393+
form_params = []
394+
local_var_files = {}
395+
396+
body_params = None
397+
# Authentication setting
398+
auth_settings = ['basicAuth'] # noqa: E501
399+
400+
return self.api_client.call_api(
401+
'/competitions/data/download-all/{id}', 'GET',
402+
path_params,
403+
query_params,
404+
header_params,
405+
body=body_params,
406+
post_params=form_params,
407+
files=local_var_files,
408+
response_type='Result', # noqa: E501
409+
auth_settings=auth_settings,
410+
async_req=params.get('async_req'),
411+
_return_http_data_only=params.get('_return_http_data_only'),
412+
_preload_content=params.get('_preload_content', True),
413+
_request_timeout=params.get('_request_timeout'),
414+
collection_formats=collection_formats)
415+
327416
def competitions_data_list_files(self, id, **kwargs): # noqa: E501
328417
"""List competition data files # noqa: E501
329418

kaggle/api/kaggle_api_extended.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666

6767

6868
class KaggleApi(KaggleApi):
69-
__version__ = '1.5.5'
69+
__version__ = '1.5.6'
7070

7171
CONFIG_NAME_PROXY = 'proxy'
7272
CONFIG_NAME_COMPETITION = 'competition'
@@ -682,8 +682,7 @@ def competition_download_files(self,
682682
path=None,
683683
force=False,
684684
quiet=True):
685-
""" a wrapper to competition_download_file to download all competition
686-
files.
685+
""" downloads all competition files.
687686
688687
Parameters
689688
=========
@@ -692,12 +691,21 @@ def competition_download_files(self,
692691
force: force the download if the file already exists (default False)
693692
quiet: suppress verbose output (default is True)
694693
"""
695-
files = self.competition_list_files(competition)
696-
if not files:
697-
print('This competition does not have any available data files')
698-
for file_name in files:
699-
self.competition_download_file(competition, file_name.ref, path,
700-
force, quiet)
694+
if path is None:
695+
effective_path = self.get_default_download_dir(
696+
'competitions', competition)
697+
else:
698+
effective_path = path
699+
700+
response = self.process_response(
701+
self.competitions_data_download_files_with_http_info(
702+
id=competition, _preload_content=False))
703+
url = response.retries.history[0].redirect_location.split('?')[0]
704+
outfile = os.path.join(effective_path,
705+
competition + '.' + url.split('.')[-1])
706+
707+
if force or self.download_needed(response, outfile, quiet):
708+
self.download_file(response, outfile, quiet)
701709

702710
def competition_download_cli(self,
703711
competition,

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
setup(
2121
name='kaggle',
22-
version='1.5.5',
22+
version='1.5.6',
2323
description='Kaggle API',
2424
long_description=
2525
('Official API for https://www.kaggle.com, accessible using a command line '

0 commit comments

Comments
 (0)