@@ -0,0 +1,1308 @@
+import json%0Aimport logging%0Aimport os%0A%0A%0Alogger = logging.getLogger(__name__)%0A%0A%0Adef get_title_from_file_path(full_path, base_path):%0A%09rel_path = os.path.relpath(full_path, base_path)%0A%0A%09rel_path_no_ext = os.path.splitext(rel_path)%5B0%5D%0A%0A%09return rel_path_no_ext.replace(os.sep, ' ')%0A%0A%0Adef split_text(text, sep='='):%0A%09i = text.find(sep)%0A%09return (text%5B:i%5D, text%5Bi + 1:%5D)%0A%0A%0Adef get_links_from_files(base_path):%0A%09all_links = dict()%0A%0A%09for parent_path, folders, files in os.walk(base_path):%0A%09%09logger.debug('Reading folder %25s', parent_path)%0A%0A%09%09for file_name in files:%0A%09%09%09if '.txt' == os.path.splitext(file_name)%5B1%5D:%0A%09%09%09%09full_path = os.path.join(parent_path, file_name)%0A%0A%09%09%09%09logger.debug('Reading file %25s', full_path)%0A%0A%09%09%09%09with open(full_path) as r:%0A%09%09%09%09%09details = dict(%5Bsplit_text(line.strip()) for line in r%5D)%0A%0A%09%09%09%09%09link = details.get('link')%0A%0A%09%09%09%09%09if link is not None:%0A%09%09%09%09%09%09title = get_title_from_file_path(full_path, base_path)%0A%0A%09%09%09%09%09%09all_links%5Btitle%5D = link%0A%0A%09%09%09%09%09%09logger.debug('Added link %25s', link)%0A%0A%09return all_links%0A%0A%0Aif '__main__' == __name__:%0A%09logging.basicConfig(level=logging.DEBUG)%0A%0A%09cur_path = os.getcwd()%0A%0A%09data_path = os.path.join(cur_path, 'data')%0A%0A%09json_path = os.path.join(cur_path, 'data.json')%0A%0A%09all_links = get_links_from_files(data_path)%0A%0A%09with open(json_path, 'w') as w:%0A%09%09json.dump(all_links, w)%0A

Add compile Python script