-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgen_pdf.py
More file actions
executable file
·67 lines (58 loc) · 2.16 KB
/
gen_pdf.py
File metadata and controls
executable file
·67 lines (58 loc) · 2.16 KB
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
#!/home/kirito/miniconda3/bin/python
import csv
import os
folder = "./_data/summer/"
files = os.listdir(folder)
files = [file for file in files if ".csv" in file]
md_file = "./_data/summer/summer.md"
pdf_file = "./_pages/summer.pdf"
f = open(md_file, "w")
f.close()
f = open(md_file, "a")
pandoc_options = [
"fontfamily: FiraSans",
"fontfamilyoptions: sfdefault",
"fontsize: 11pt",
"header-includes: |",
"\t\\usepackage{hyperref,booktabs,colortbl,color,xcolor}",
"\t\\usepackage[textheight=70cm,margin=2cm]{geometry}",
]
frontmatter = "---\n" + "\n".join(pandoc_options) + "\n---\n"
f.write(frontmatter)
f.write("\\def\\arraystretch{1.2}\n")
f.write("\\section*{\\textcolor{blue}{Summer Internship Programs}}\n")
f.write("\\vspace{-20pt}\n\\rule{\\textwidth}{2pt}\n\n")
f.write(
"The institute names in the left columns are hyperlinks to the respective webpages.\n"
)
titles = ["Active Programs", "Currently Inactive/Closed", "Yet to be Declared"]
files = sorted(files)
assert len(titles) == len(files)
for title, file in zip(titles, files):
f.write("\\vspace{10pt}\n")
f.write("\\begin{minipage}{\\textwidth}\n")
f.write("\\subsection*{\\textcolor{purple}{" + title + "}}" + "\n\n")
f.write("\\vspace{-15pt}\n\\rule{\\textwidth}{1.5pt}\\\\\n")
data = list(csv.reader(open(folder + file, "r"), delimiter=","))
ncols = len(data[0])
f.write("\\begin{center}\n\\begin{tabular}{l" + "c" * (ncols - 2) + "}\n")
head = ["\\textcolor{white}{\\textbf{" + datum + "}}" for datum in data[0]]
f.write("\\rowcolor{darkgray}\n")
f.write(" & ".join(head[:-1]) + "\\\\\n")
colors = ["white", "lightgray"]
for row in data[1:]:
colors = [colors[-1]] + [colors[0]]
if len(row) == 0:
continue
inst = row[0]
link = row[-1]
f.write("\\rowcolor{" + colors[0] + "}\n")
f.write(
"\href{" + link + "}{" + inst + "} & " + " & ".join(row[1:-1]) + " \\\\\n"
)
f.write("\\end{tabular}\n\\end{center}\n")
f.write("\\end{minipage}\\\n")
f.write("\\rule{\\textwidth}{2pt}\n")
f.close()
out = os.system("pandoc " + md_file + " -t latex " + " -o " + pdf_file)
assert out == 0