forked from harleyszhang/cv_note
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlatex2pic.py
84 lines (71 loc) · 3.05 KB
/
latex2pic.py
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import re
from urllib.parse import quote
import sys, os
import os.path as osp
current_dir = os.path.abspath(os.path.dirname(__file__)).replace('\\', '/')
sys.path.append(current_dir)
def count_file_num(self, directory, file_type = "md"):
"""count the number of json/image/.py files in directory path.
Args:
directory: root path of dat files directory.
Returns:
file_list: The file path list that require specified file type("dat").
file_number: total file number of files that require specified file type.
"""
if file_type == "image":
file_types = ['jpg', 'JPG', 'png', 'PNG']
else:
file_types = []
file_types.append(file_type)
file_list = [] # specified file list
size = 0
try:
# traverse subfolders in root directory
for root, _, files in os.walk(directory): # sub_dir is 3 tuple object
if len(files) >= 1:
for sub_file in files:
sub_file = osp.join(root, sub_file).replace('\\', '/')
file_extension = osp.splitext(sub_file)[1].strip('.') # 'png'?
if not file_extension in file_types:
continue
else:
file_list.append(sub_file)
size += os.path.getsize(sub_file)
except Exception as e:
print(e)
file_number = len(file_list)
print(149*"*")
print('In 【"%s"】 directory, all 【 "%s" 】 file size is: %.3f Mb.' % (directory, file_type, size / 1024 / 1024))
print("There are 【 %d 】 %s files." % (file_number, file_type))
print(149*"*")
return file_list, file_number
def show_sgl_github_md(md_path):
assert os.path.splitext(md_path)[1] == '.md'
text = open(md_path, encoding="utf-8").read()
parts = text.split("$$")
for i, part in enumerate(parts):
if i & 1:
parts[i] = f')})'
text_out = "\n\n".join(parts)
lines = text_out.split('\n')
for lid, line in enumerate(lines):
parts = re.split(r"\$(.*?)\$", line)
for i, part in enumerate(parts):
if i & 1:
parts[i] = f')})'
lines[lid] = ' '.join(parts)
text_out = "\n".join(lines)
new_file_name = os.path.basename(md_path) + '_show'
new_file_path = osp.join(os.path.dirname(md_path), new_file_name)
with open("./深度学习/神经网络压缩算法总结new.md", "w", encoding='utf-8') as f:
f.write(text_out)
def show_multi_github_md(md_file):
pass
if __name__ == "__main__":
path = "C:/Users/zhanghonggao/Documents/my_project/2020_algorithm_intern_information-master"
if os.path.isfile(path):
show_sgl_github_md(path)
elif os.path.isdir(path):
show_multi_github_md(path)
else:
print(FileNotFoundError)