def test_download(): """ """ temp_dir = pathlib.Path(tempfile.mkdtemp()) text_file = ("https://raw.githubusercontent.com/" "nazrulworld/fhir-parser/master/archives/" "HL7/FHIR/STU3/3.0.1-version.info") html_file = "" # noqa: F841 json_file = "" # noqa: F841 zip_file = ("https://github.com/nazrulworld/fhir-parser/" "raw/master/archives/HL7/FHIR/STU3/3.0.2-examples-json.zip") file1 = fhirspec.download(text_file, temp_dir) assert file1.exists() file2 = fhirspec.download(zip_file, temp_dir) assert file2.exists() shutil.rmtree(temp_dir)
def download_archive(release: FHIR_VERSION, temp_location: pathlib.Path) -> pathlib.Path: """ """ assert release != FHIR_VERSION.DEFAULT release_name = release.name version = release.value fullurl = BASE_URL.format(release=release_name, version=version) logger.info("Archive file has been downloaded from {0}".format(fullurl)) return download(fullurl, temp_location)
def download(self, filename): """ Download the given file located on the server. :returns: The local file name in our cache directory the file was downloaded to """ import requests # import here as we can bypass its use with a manual download url = self.base_url + "/" + filename print(url) return download(url, download_directory=self.cache)
def ensure_static_files() -> typing.Dict[str, typing.List[pathlib.Path]]: """ """ base_url = "https://github.com/nazrulworld/fhir-parser/raw/master/archives/HL7/FHIR" files = ("definitions-json.zip", "examples-json.zip", "version.info") results: typing.Dict[str, typing.List[pathlib.Path]] = {} for item in (("R4", "4.0.1"), ("STU3", "3.0.2")): release, version = item directory = DEFINITION_DIR / release / version if not directory.exists(): directory.mkdir(parents=True) results[release] = list() for file_suffix in files: filename = version + "-" + file_suffix if not (directory / filename).exists(): file_location = fhirspec.download( base_url + "/" + release + "/" + filename, directory ) results[release].append(file_location) else: results[release].append(directory / filename) return results