-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpy2journal.py
More file actions
96 lines (75 loc) · 2.36 KB
/
py2journal.py
File metadata and controls
96 lines (75 loc) · 2.36 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
from os import listdir,chdir,getcwd,remove
from os.path import isfile,join
scl=.5 # Enter the fraction to scale screenshots
root='Enter the Journal folder path here' # Enter the path of journal directory here.
fil=open("ip.tex","w")
fil.write("\\documentclass[12pt,a4paper]{report}\n\\usepackage{graphicx}\n")
fil.write("\\addtolength{\\oddsidemargin}{-.875in}\n")
fil.write("\\addtolength{\\evensidemargin}{-.875in}\n")
fil.write("\\addtolength{\\textwidth}{1.75in}\n")
fil.write("\\addtolength{\\topmargin}{-.875in}\n")
fil.write("\\addtolength{\\textheight}{1.75in}\n")
fil.write("\\usepackage[T1]{fontenc}\n")
fil.write("\\begin{document}\n")
root_dir=[f for f in listdir(root)]
tot_labs=len(root_dir)
d=1
for i in range(tot_labs):
s=1
q=1
c=1
pre_dir='Lab'+str(d)
if pre_dir in root_dir:
files=[x for x in listdir(join(root,pre_dir))]
fil_n=[x for x in files if x[0]=='q']
temp_files=[x for x in fil_n if x[-1]=='~']
for tem in temp_files:
fil_n.remove(tem)
pre_dir_name='LAB'+' '+str(d)
#Prints the Lab number
string='\\begin{center}\n\\Huge\\textbf{'+pre_dir_name+'}\\\\\n'
fil.write(string)
# Prints Labname
lab_name_str=join(join(root,pre_dir),'ln.txt')
fileln=open(lab_name_str,"r")
ln=fileln.readline()
fil.write("\\large{%s}"%ln)
fileln.close()
fil.write("\n\\end{center}\n\\vspace{1.0cm}\n")
fil.write("\\begin{enumerate}\n")
for j in range(len(fil_n)):
# Prints Question.
que='q'+str(q)+'.txt'
que_name_str=join(join(root,pre_dir),que)
fileq=open(que_name_str,"r")
qu=fileq.readline()
fil.write("\\item\\textbf{%s}\n"%qu)
q=q+1
fileq.close()
#Prints Code
sp_chr="#$%&^_{}!"
cde='c'+str(c)+'.m'
code_str=join(join(root,pre_dir),cde)
filec=open(code_str,"r")
code=filec.read()
fil.write("\\begin{verbatim}\n")
fil.write(code)
fil.write("\\end{verbatim}")
c=c+1
filec.close()
#Prints screenshot
ss=1
s_n=[x for x in files if x[:2]=='s'+str(s)]
if s_n!=0:
for k in range(len(s_n)):
s_name=join(join(root,pre_dir),'s'+str(s)+'-'+str(ss)+'.png')
fil.write("\n\\fbox{\\includegraphics[scale=scl]{%s}\\\}"%s_name)
ss=ss+1
s=s+1
fil.write("\\vspace{0.5cm}\n")
fil.write("\n\\end{enumerate}")
fil.write("\n\\pagebreak")
root_dir.remove(pre_dir)
d=d+1
fil.write("\n\\end{document}")
fil.close()