示例#1
0
def main():
    """Generate dataset and create it in HDX"""

    with Download() as downloader:
        configuration = Configuration.read()
        base_url = configuration['base_url']
        dataset_tags_mapping = configuration['dataset_tags_mapping']
        geonodetohdx = GeoNodeToHDX(base_url, downloader)
        countrydata = {'iso3': 'MMR', 'name': 'Myanmar', 'layers': None}
        metadata = {'maintainerid': '196196be-6037-4488-8b71-d786adf4c081',
                    'orgid': 'bde18602-2e92-462a-8e88-a0018a7b13f9'}

        datasets = geonodetohdx.generate_datasets_and_showcases(metadata, countrydata=countrydata,
                                                                get_date_from_title=True,
                                                                process_dataset_name=process_dataset_name,
                                                                dataset_tags_mapping=dataset_tags_mapping,
                                                                updated_by_script='HDX Scraper: MIMU GeoNode')
        geonodetohdx.delete_other_datasets(datasets, metadata)
    def test_delete_other_datasets(self, search_datasets, configuration,
                                   downloader):
        datasets = list()

        def delete_from_hdx(dataset):
            datasets.append(dataset)

        geonodetohdx = GeoNodeToHDX('http://xxx', downloader)
        geonodetohdx.geonode_urls.append('https://ogcserver.gis.wfp.org')
        geonodetohdx.delete_other_datasets(self.wfpnames,
                                           self.wfpmetadata,
                                           delete_from_hdx=delete_from_hdx)
        assert len(datasets) == 0

        geonodetohdx.delete_other_datasets(self.mimunames,
                                           self.mimumetadata,
                                           delete_from_hdx=delete_from_hdx)
        assert datasets[0]['name'] == self.wfpdatasets[0]['name']
        assert datasets[1]['name'] == self.wfpdatasets[1]['name']
        geonodetohdx = GeoNodeToHDX('http://yyy', downloader)
        datasets = list()
        geonodetohdx.delete_other_datasets(self.mimunames,
                                           self.mimumetadata,
                                           delete_from_hdx=delete_from_hdx)
        assert len(datasets) == 0