diff --git a/src/main.py b/src/main.py index 471bcf8..769e8fa 100644 --- a/src/main.py +++ b/src/main.py @@ -1,3 +1,4 @@ +import json import os from distutils import util @@ -139,6 +140,20 @@ def download_json_plus_images(api, project, dataset_ids): save_image_meta=True, ) sly.logger.info("Project {!r} has been successfully downloaded.".format(project.name)) + sly.logger.info("Start building files...") + + tf_urls_path = "/cache/released_datasets.json" + local_save_path = sly.app.get_data_dir() + "/tmp/released_datasets.json" + if api.file.exists(TEAM_ID, tf_urls_path): + api.file.download(TEAM_ID, tf_urls_path, local_save_path) + with open(local_save_path, "r") as f: + urls = json.load(f) + else: + raise FileNotFoundError(f"File not found: '{tf_urls_path}'") + + build_license(urls[project.name]["markdown"]["LICENSE"], download_dir) + build_readme(urls[project.name]["markdown"]["README"], download_dir) + sly.logger.info("'LICENSE.md' and 'README.md' were successfully built.") def download_only_json(api, project, dataset_ids): @@ -182,6 +197,19 @@ def download_only_json(api, project, dataset_ids): sly.logger.info("Total number of images: {!r}".format(total_images)) +def build_license(license_content: str, download_dir: str): + license_path = os.path.join(download_dir, "LICENSE.md") + print(license_content) + with open(license_path, "w") as license_file: + license_file.write(license_content) + + +def build_readme(readme_content: str, download_dir: str): + readme_path = os.path.join(download_dir, "README.md") + with open(readme_path, "w") as license_file: + license_file.write(readme_content) + + def main(): sly.logger.info( "Script arguments",