def downloadDataset(id, dest): api = KaggleApi(ApiClient()) api.authenticate() api.dataset_download_files(id, dest, quiet=False, unzip=True) print("download complete")
def getDatasets(self, search, mine): api = KaggleApi(ApiClient()) api.authenticate() return json.JSONEncoder().encode([ convert_ds(item) for item in api.dataset_list(search=search, mine=mine) ])
def downloadCompetitionFiles(dataset_id, dest): api = KaggleApi(ApiClient()) api.authenticate() api.competition_download_files(dataset_id, dest, True, False) unpack_all_zips(dest) print("download complete")
def getCompetitions(self, search, mine): api = KaggleApi(ApiClient()) api.authenticate() return json.JSONEncoder().encode([ convert_ds(item) for item in api.competitions_list( "entered" if mine else "general", "all", "recentlyCreated", 1, search) ])
def __init__(self, config, *, context, **kwargs): super(Application, self).__init__(config, debug=config.debug, context=context, **kwargs) main_html = pathlib.Path(__file__).parent / 'templates' / 'main.html' self.main_html = main_html.read_text(encoding='utf-8') configuration = Configuration() configuration.username = self.context.config.kaggle.user configuration.password = self.context.config.kaggle.key self.api_client = ApiClient(configuration) self.kaggle_api = NoAuthKaggleApi(self.api_client)
def downloadCompetitionFiles(id, dest): api = KaggleApi(ApiClient()) api.authenticate() api.competition_download_files(id, dest, True, False) for item in os.listdir(dest): path = os.path.join(dest, item) if zipfile.is_zipfile(path): new_dir = path[0:path.rindex(".")] with zipfile.ZipFile(path) as zip: zip.extractall(new_dir) print("removing: " + path) os.remove(path) print("download complete")
def to_dataset(src, experiments, name, data=False): try: from kaggle.api.kaggle_api_extended import KaggleApi from kaggle.api_client import ApiClient except: print("Kaggle not found or user credentials not provided.") return api = KaggleApi(ApiClient()) api.authenticate() dest = os.path.expanduser("~/.musket_core/proj_to_dataset") if os.path.exists(dest): shutil.rmtree(dest, ignore_errors=True) utils.ensure(dest) visit_tree( src, lambda path: utils.throw("zip files not allowed!") if path.lower().endswith(".zip") else ()) if data: src = os.path.join(src, "data") dest = os.path.join(dest, "data") shutil.copytree(src, dst) else: utils.collect_project(src, dest, True, False, experiments) api.dataset_initialize(dest) metapath = os.path.join(dest, "dataset-metadata.json") with open(metapath, "r") as f: metadata = f.read() metadata = metadata.replace("INSERT_SLUG_HERE", name).replace("INSERT_TITLE_HERE", name) with open(metapath, "w") as f: f.write(metadata) id = json.loads(metadata)["id"] sets = [] page = 1 resp = api.dataset_list(mine=True, search=name, page=page) while len(resp): sets += resp page += 1 resp = api.dataset_list(mine=True, search=name, page=page) if id in [str(item) for item in sets]: api.dataset_create_version(dest, delete_old_versions=True, convert_to_csv=False, version_notes="new version", dir_mode="zip") else: api.dataset_create_new(dest, convert_to_csv=False, dir_mode="zip")
#!/usr/bin/python # # Copyright 2018 Kaggle Inc # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # coding=utf-8 from __future__ import absolute_import from kaggle.api.kaggle_api_extended import KaggleApi from kaggle.api_client import ApiClient api = KaggleApi(ApiClient()) api.authenticate()
def get_kaggle_api() -> Any: return KaggleApi(ApiClient())
from kaggle.api_client import ApiClient from kaggle.api.kaggle_api_extended import KaggleApi kaggle = KaggleApi(ApiClient()) kaggle.authenticate()
def __init__(self, api_client=None): if api_client is None: api_client = ApiClient() self.api_client = api_client