def merge_cities_file(cls, _format="csv"): """ Transform the file for the RH :param _format: two possibilities: - "csv": merge the extracted cities into a csv file - "json": merge the extracted cities into a json file :return: """ data = {} if _format == "json" else [] for place_type in cls.PLACE_TYPES: folder = os.path.join(cls.CITIES_FOLDER_NAME, place_type) for filename in FileManager.list_files(folder): cities = FileManager.read(os.path.join(folder, filename), _format="json") if cities['status'] == 'SUCCESS': cities = cities['nodes'] if _format == "json": data.update(cls.to_json(cities)) elif _format == "csv": data = cls.to_csv(data, cities) if _format == "csv": # we complete the line with None. We don't have the name ine each language l = len(data[0]) for line in data[1:]: for i in range(len(line), l): line.append(None) FileManager.write(os.path.join( cls.CITIES_FOLDER_NAME, cls.WORLD_CITIES_FILE.format(format=_format)), data, _format=_format)
def show_select_dir_dialog(self, event): """ Show the DirDialog and print the user's choice to stdout """ dlg = wx.DirDialog(self, "Choose a directory:", style=wx.DD_DEFAULT_STYLE # | wx.DD_DIR_MUST_EXIST # | wx.DD_CHANGE_DIR ) if dlg.ShowModal() == wx.ID_OK: print("You chose" + dlg.GetPath()) self.folder_path = dlg.GetPath() self.selected_folder_label.SetLabel("Folder:" + self.folder_path) self.files_in_folder = FileManager.list_files(self.folder_path, self.search_string) self.refresh_list_view() print(FileManager.find_urls_in_list(self.files_in_folder)) dlg.Destroy()