-
Notifications
You must be signed in to change notification settings - Fork 804
/
generateReadme.py
65 lines (52 loc) · 1.99 KB
/
generateReadme.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import urllib
""" generate readme.md """
__author__ = 'Wang Zhe'
paper_class_map = {}
paper_map = {}
file_object = open('./README.md')
all_lines = file_object.readlines()
file_object.close()
out_file = open('./README.md', 'w')
paper_class_flag = 0
paper_class_name = ""
paper_flag = 0
paper_name = ""
catalog_flag = 0
for line in all_lines:
if catalog_flag != 1:
out_file.write(line)
if line.startswith("##"):
catalog_flag = 1
if paper_class_flag == 1 and not line.startswith("*") and not line.startswith("#"):
paper_class_map[paper_class_name] = line.strip()
print paper_class_name, line.strip()
paper_class_flag = 0
if paper_flag == 1 and not line.startswith("*") and not line.startswith("#"):
paper_map[paper_name] = line.strip()
print "\t", paper_name, line.strip()
paper_flag = 0
if catalog_flag == 1:
if line.startswith("*"):
paper_flag = 1
paper_name = line[line.find("[")+1:line.find("]")].strip()
if line.startswith("###"):
paper_class_flag = 1
paper_class_name = line[3:].strip()
github_root = "https://github.com/wzhe06/Reco-papers/blob/master/"
all_dir = os.listdir("./")
for one_dir in all_dir:
if os.path.isdir(one_dir) and not one_dir.startswith('.'):
out_file.write("\n### " + one_dir+"\n")
if one_dir.strip() in paper_class_map:
out_file.write(paper_class_map[one_dir.strip()] + "\n")
all_sub_files = os.listdir(one_dir)
for one_file in all_sub_files:
if not os.path.isdir(one_file) and not one_file.startswith('.'):
out_file.write("* [" + ('.').join(one_file.split('.')[:-1]) + "]("+github_root + urllib.quote(one_dir.strip())+"/"
+ urllib.quote(one_file.strip())+") <br />\n")
if one_file.strip() in paper_map:
out_file.write(paper_map[one_file.strip()] + "\n")
out_file.close()