0 功能

将文件夹中的PDF文件,转化成markdwon格式的链接语法,即[]()格式,输入自己的github存放地址以及文件夹路径即可。

1 代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# _*_ coding=utf-8 _*_
'''

这个程序用来整理文件夹中的PDF文件,将其转化成Markdown格式的链接,即[]()的形式
'''
import os,re

def get_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] is not None:
for book in _book_list:
if ".pdf" in book:
pdf_list.append(book)
return pdf_list

def get_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

def show_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 not in used:
print("- {}".format(i))


def main():
book_list = get_book_lists()
urls = get_url_links(book_list)
type_name = ["Python","SQL","TCP-IP详解","Kali_Linux无线网络渗透测试","HTTP","Shell","Linux"]
show_markdown_format(book_list,urls,type_name)


if __name__ == '__main__':
main()

写在最后

欢迎大家关注鄙人的公众号【麦田里的守望者zhg】,让我们一起成长,谢谢。
微信公众号