defget_book_lists(): root_dir = r"J:\电子书" dir_tree = os.walk(root_dir) sub_dir = dir_tree.__next__()[1] pdf_list = [] for sub in sub_dir: for _sub in os.walk(root_dir + "\\" + str(sub)): _book_list = _sub[-1] if _sub[1] isnotNone: for book in _book_list: if".pdf"in book: pdf_list.append(book) return pdf_list
defget_url_links(book_list): urls = [] url = "https://jums.club/images/article/pdf" for book in book_list: book = re.sub(" |:|:|,|,|(|)|\(|\)","_",book) book = re.sub("《|》","",book) _url = "[{}]({}/{}) ".format(book[:-4], url, book) urls.append(_url)
return urls
defshow_markdown_format(book_list,urls,type_name): dict = {} for i in type_name: dict[i] = [] # print(dict) dict["other"] = [] used = [] for each_url in urls: for each_name in type_name: if each_name in each_url: _ = dict[each_name] _.append(each_url) used.append(each_url) print(len(urls)) print(len(used)) for each in type_name: _list = dict[each] print(each + ": ") for _url in _list: print("- {}".format(_url)) print("other: ") for i in urls: if i notin used: print("- {}".format(i))