@@ -86,6 +86,29 @@ class KaggleApi(KaggleApi):
86
86
config_values = {}
87
87
already_printed_version_warning = False
88
88
89
+ # Kernels valid types
90
+ valid_push_kernel_types = ['script' , 'notebook' ]
91
+ valid_push_language_types = ['python' , 'r' , 'rmarkdown' ]
92
+ valid_list_languages = ['all' , 'python' , 'r' , 'sqlite' , 'julia' ]
93
+ valid_list_kernel_types = ['all' , 'script' , 'notebook' ]
94
+ valid_list_output_types = ['all' , 'visualization' , 'data' ]
95
+ valid_list_sort_by = ['hotness' , 'commentCount' , 'dateCreated' , 'dateRun' ,
96
+ 'relevance' , 'scoreAscending' , 'scoreDescending' , 'viewCount' , 'voteCount' ]
97
+
98
+ # Competitoins valid types
99
+ valid_competition_groups = ['general' , 'entered' , 'inClass' ]
100
+ valid_competition_categories = [
101
+ 'all' , 'featured' , 'research' , 'recruitment' , 'gettingStarted' , 'masters' , 'playground' ]
102
+ valid_competition_sort_by = ['grouped' , 'prize' , 'earliestDeadline' ,
103
+ 'latestDeadline' , 'numberOfTeams' , 'recentlyCreated' ]
104
+
105
+ # Datasets valid types
106
+ valid_dataset_file_types = ['all' , 'csv' , 'sqlite' , 'json' , 'bigQuery' ]
107
+ valid_dataset_license_names = ['all' , 'cc' , 'gpl' , 'odb' , 'other' ]
108
+ valid_dataset_sizes = ['all' , 'small' , 'medium' , 'large' ]
109
+ valid_dataset_sort_bys = ['hottest' , 'votes' ,
110
+ 'updated' , 'active' , 'published' ]
111
+
89
112
# Hack for https://github.com/Kaggle/kaggle-api/issues/22 / b/78194015
90
113
if six .PY2 :
91
114
reload (sys )
@@ -380,30 +403,21 @@ def competitions_list(self,
380
403
381
404
page: the page to return (default is 1)
382
405
search: a search term to use (default is empty string)
383
- sort_by: how to sort the result, see valid_sort_by for options
406
+ sort_by: how to sort the result, see valid_competition_sort_by for options
384
407
category: category to filter result to
385
408
group: group to filter result to
386
409
"""
387
- valid_groups = ['general' , 'entered' , 'inClass' ]
388
- if group and group not in valid_groups :
410
+ if group and group not in self .valid_competition_groups :
389
411
raise ValueError ('Invalid group specified. Valid options are ' +
390
- str (valid_groups ))
412
+ str (self . valid_competition_groups ))
391
413
392
- valid_categories = [
393
- 'all' , 'featured' , 'research' , 'recruitment' , 'gettingStarted' ,
394
- 'masters' , 'playground'
395
- ]
396
- if category and category not in valid_categories :
414
+ if category and category not in self .valid_competition_categories :
397
415
raise ValueError ('Invalid category specified. Valid options are ' +
398
- str (valid_categories ))
416
+ str (self . valid_competition_categories ))
399
417
400
- valid_sort_by = [
401
- 'grouped' , 'prize' , 'earliestDeadline' , 'latestDeadline' ,
402
- 'numberOfTeams' , 'recentlyCreated'
403
- ]
404
- if sort_by and sort_by not in valid_sort_by :
418
+ if sort_by and sort_by not in self .valid_competition_sort_by :
405
419
raise ValueError ('Invalid sort_by specified. Valid options are ' +
406
- str (valid_sort_by ))
420
+ str (self . valid_competition_sort_by ))
407
421
408
422
competitions_list_result = self .process_response (
409
423
self .competitions_list_with_http_info (
@@ -809,35 +823,31 @@ def dataset_list(self,
809
823
810
824
Parameters
811
825
==========
812
- sort_by: how to sort the result, see valid_sort_bys for options
813
- size: the size of the dataset, see valid_sizes for string options
814
- file_type: the format, see valid_file_types for string options
815
- license_name: string descriptor for license, see valid_license_names
826
+ sort_by: how to sort the result, see valid_dataset_sort_bys for options
827
+ size: the size of the dataset, see valid_dataset_sizes for string options
828
+ file_type: the format, see valid_dataset_file_types for string options
829
+ license_name: string descriptor for license, see valid_dataset_license_names
816
830
tag_ids: tag identifiers to filter the search
817
831
search: a search term to use (default is empty string)
818
832
user: username to filter the search to
819
833
mine: boolean if True, group is changed to "my" to return personal
820
834
page: the page to return (default is 1)
821
835
"""
822
- valid_sort_bys = ['hottest' , 'votes' , 'updated' , 'active' , 'published' ]
823
- if sort_by and sort_by not in valid_sort_bys :
836
+ if sort_by and sort_by not in self .valid_dataset_sort_bys :
824
837
raise ValueError ('Invalid sort by specified. Valid options are ' +
825
- str (valid_sort_bys ))
838
+ str (self . valid_dataset_sort_bys ))
826
839
827
- valid_sizes = ['all' , 'small' , 'medium' , 'large' ]
828
- if size and size not in valid_sizes :
840
+ if size and size not in self .valid_dataset_sizes :
829
841
raise ValueError ('Invalid size specified. Valid options are ' +
830
- str (valid_sizes ))
842
+ str (self . valid_dataset_sizes ))
831
843
832
- valid_file_types = ['all' , 'csv' , 'sqlite' , 'json' , 'bigQuery' ]
833
- if file_type and file_type not in valid_file_types :
844
+ if file_type and file_type not in self .valid_dataset_file_types :
834
845
raise ValueError ('Invalid file type specified. Valid options are '
835
- + str (valid_file_types ))
846
+ + str (self . valid_dataset_file_types ))
836
847
837
- valid_license_names = ['all' , 'cc' , 'gpl' , 'odb' , 'other' ]
838
- if license_name and license_name not in valid_license_names :
848
+ if license_name and license_name not in self .valid_dataset_license_names :
839
849
raise ValueError ('Invalid license specified. Valid options are ' +
840
- str (valid_license_names ))
850
+ str (self . valid_dataset_license_names ))
841
851
842
852
if int (page ) <= 0 :
843
853
raise ValueError ('Page number must be >= 1' )
@@ -879,10 +889,10 @@ def dataset_list_cli(self,
879
889
880
890
Parameters
881
891
==========
882
- sort_by: how to sort the result, see valid_sort_bys for options
883
- size: the size of the dataset, see valid_sizes for string options
884
- file_type: the format, see valid_file_types for string options
885
- license_name: string descriptor for license, see valid_license_names
892
+ sort_by: how to sort the result, see valid_dataset_sort_bys for options
893
+ size: the size of the dataset, see valid_dataset_sizes for string options
894
+ file_type: the format, see valid_dataset_file_types for string options
895
+ license_name: string descriptor for license, see valid_dataset_license_names
886
896
tag_ids: tag identifiers to filter the search
887
897
search: a search term to use (default is empty string)
888
898
user: username to filter the search to
@@ -1525,9 +1535,9 @@ def kernels_list(self,
1525
1535
mine: if true, group is specified as "my" to return personal kernels
1526
1536
user: filter results to a specific user
1527
1537
language: the programming language of the kernel
1528
- kernel_type: the type of kernel, one of valid_kernel_types (str)
1529
- output_type: the output type, one of valid_output_types (str)
1530
- sort_by: if defined, sort results by this string (valid_sort_by )
1538
+ kernel_type: the type of kernel, one of valid_list_kernel_types (str)
1539
+ output_type: the output type, one of valid_list_output_types (str)
1540
+ sort_by: if defined, sort results by this string (valid_list_sort_by )
1531
1541
"""
1532
1542
if int (page ) <= 0 :
1533
1543
raise ValueError ('Page number must be >= 1' )
@@ -1538,31 +1548,25 @@ def kernels_list(self,
1538
1548
if page_size > 100 :
1539
1549
page_size = 100
1540
1550
1541
- valid_languages = ['all' , 'python' , 'r' , 'sqlite' , 'julia' ]
1542
- if language and language not in valid_languages :
1551
+ if language and language not in self .valid_list_languages :
1543
1552
raise ValueError ('Invalid language specified. Valid options are ' +
1544
- str (valid_languages ))
1553
+ str (self . valid_list_languages ))
1545
1554
1546
- valid_kernel_types = ['all' , 'script' , 'notebook' ]
1547
- if kernel_type and kernel_type not in valid_kernel_types :
1555
+ if kernel_type and kernel_type not in self .valid_list_kernel_types :
1548
1556
raise ValueError (
1549
1557
'Invalid kernel type specified. Valid options are ' +
1550
- str (valid_kernel_types ))
1558
+ str (self . valid_list_kernel_types ))
1551
1559
1552
- valid_output_types = ['all' , 'visualization' , 'data' ]
1553
- if output_type and output_type not in valid_output_types :
1560
+ if output_type and output_type not in self .valid_list_output_types :
1554
1561
raise ValueError (
1555
1562
'Invalid output type specified. Valid options are ' +
1556
- str (valid_output_types ))
1557
-
1558
- valid_sort_by = [
1559
- 'hotness' , 'commentCount' , 'dateCreated' , 'dateRun' , 'relevance' ,
1560
- 'scoreAscending' , 'scoreDescending' , 'viewCount' , 'voteCount'
1561
- ]
1562
- if sort_by and sort_by not in valid_sort_by :
1563
+ str (self .valid_list_output_types ))
1564
+
1565
+ if sort_by and sort_by not in self .valid_list_sort_by :
1563
1566
raise ValueError (
1564
1567
'Invalid sort by type specified. Valid options are ' +
1565
- str (valid_sort_by ))
1568
+ str (self .valid_list_sort_by ))
1569
+
1566
1570
if sort_by == 'relevance' and search == '' :
1567
1571
raise ValueError ('Cannot sort by relevance without a search term.' )
1568
1572
@@ -1650,8 +1654,8 @@ def kernels_initialize(self, folder):
1650
1654
'id' : username + '/INSERT_KERNEL_SLUG_HERE' ,
1651
1655
'title' : 'INSERT_TITLE_HERE' ,
1652
1656
'code_file' : 'INSERT_CODE_FILE_PATH_HERE' ,
1653
- 'language' : 'INSERT_LANGUAGE_HERE ' ,
1654
- 'kernel_type' : 'INSERT_KERNEL_TYPE_HERE ' ,
1657
+ 'language' : 'Pick one of: {' + ',' . join ( x for x in self . valid_push_language_types ) + '} ' ,
1658
+ 'kernel_type' : 'Pick one of: {' + ',' . join ( x for x in self . valid_push_kernel_types ) + '} ' ,
1655
1659
'is_private' : 'true' ,
1656
1660
'enable_gpu' : 'false' ,
1657
1661
'enable_internet' : 'false' ,
@@ -1728,19 +1732,17 @@ def kernels_push(self, folder):
1728
1732
'how slugs are determined.' %
1729
1733
'https://en.wikipedia.org/wiki/Clean_URL#Slug' )
1730
1734
1731
- valid_languages = ['python' , 'r' , 'rmarkdown' ]
1732
1735
language = self .get_or_default (meta_data , 'language' , '' )
1733
- if language not in valid_languages :
1736
+ if language not in self . valid_push_language_types :
1734
1737
raise ValueError (
1735
1738
'A valid language must be specified in the metadata. Valid '
1736
- 'options are ' + str (valid_languages ))
1739
+ 'options are ' + str (self . valid_push_language_types ))
1737
1740
1738
- valid_kernel_types = ['script' , 'notebook' ]
1739
1741
kernel_type = self .get_or_default (meta_data , 'kernel_type' , '' )
1740
- if kernel_type not in valid_kernel_types :
1742
+ if kernel_type not in self . valid_push_kernel_types :
1741
1743
raise ValueError (
1742
1744
'A valid kernel type must be specified in the metadata. Valid '
1743
- 'options are ' + str (valid_kernel_types ))
1745
+ 'options are ' + str (self . valid_push_kernel_types ))
1744
1746
1745
1747
if kernel_type == 'notebook' and language == 'rmarkdown' :
1746
1748
language = 'r'
0 commit comments