-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmake_readme.py
46 lines (38 loc) · 2.06 KB
/
make_readme.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
import os
import importlib
import matplotlib.pyplot as plt
URL = "https://github.com/HKUNLP/diagrams_toolkit"
README_STR = """# diagrams_toolkit
Source code for diagrams in the paper of HKU NLPers.
## Usage:
Search for the picture shown below which fits your needs, get into the code, download the code and adapt for your needs(e.g. change the value and color, make the generated figure in pdf format)
"""
PAPERS_DIR = './papers'
all_plots = []
for paper_dir in os.listdir(PAPERS_DIR):
# each dir is a paper,a nd this function will
if os.path.isfile(paper_dir):
# skip the README.md and other non-dir-format items
continue
for plot_dir in os.listdir(os.path.join(PAPERS_DIR, paper_dir)):
if plot_dir.endswith(".py"):
# For python, call plot function and get the fig/table path.
figure_path = importlib.import_module("papers.{}.{}".format(paper_dir, plot_dir.split('.')[0])).plot()
plt.close() # CLose the plt to avoid affecting next picture.
all_plots.append({"figure_path": "{}/blob/main/papers/{}/{}".format(URL, paper_dir, figure_path),
"code_path": "{}/blob/main/papers/{}/{}".format(URL, paper_dir, plot_dir),
"paper": paper_dir})
elif plot_dir.endswith(".tex"):
# TODO: For tex, compile it and get the fig/table path.
pass
else:
pass
HEADER = "| Figure | Code Source | Paper |\n| ---- | ---- | ---- |"
ROWS = []
for plot_info in all_plots:
ROWS.append(
"""| <a href="{}"> <img src="{}" width="300" /></a> | [code]({}) | {} |""".format(plot_info['figure_path'],
plot_info['figure_path'],
plot_info['code_path'],
plot_info['paper']))
print("{}\n\n{}\n{}".format(README_STR, HEADER, '\n'.join(ROWS)))