Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
RWTHmoodle
exam-scan
Commits
ead13ab4
Commit
ead13ab4
authored
Mar 09, 2021
by
Amrita
Browse files
handles 5digit mn+modify batch for ESiss3
parent
70d25c09
Changes
5
Hide whitespace changes
Inline
Side-by-side
batch.py
View file @
ead13ab4
...
...
@@ -3,6 +3,7 @@ import sys
import
time
import
argparse
import
supplements
import
watermark
import
encrypt
import
preparemoodle
...
...
@@ -47,6 +48,13 @@ Options:
"Default: 250"
)
parser
.
add_argument
(
"-t"
,
"--tmp"
,
default
=
"./tmp"
,
help
=
"tmp folder. Default: ./tmp/"
)
parser
.
add_argument
(
"-u"
,
"--supinfolder"
,
default
=
"./supplements"
,
help
=
"Input folder with sample solutions. Default: ./supplements"
)
parser
.
add_argument
(
"-v"
,
"--supoutfolder"
,
default
=
"./supplements_out"
,
help
=
"output folder containing watermarked sample solutions. Default: ./supplements_out"
)
parser
.
add_argument
(
"-w"
,
"--sup"
,
default
=
"0"
,
help
=
"Flag for watermarking sample solutions. 0 means no 1 means yes. Default: 0"
)
args
=
parser
.
parse_args
(
args
)
infolder
=
args
.
infolder
...
...
@@ -56,6 +64,9 @@ Options:
dpi
=
args
.
dpi
tmp
=
args
.
tmp
password
=
args
.
password
sup
=
int
(
args
.
sup
)
supoutfolder
=
args
.
supoutfolder
supinfolder
=
args
.
supinfolder
starttime
=
time
.
time
()
...
...
@@ -65,6 +76,10 @@ Options:
os
.
makedirs
(
watermark_outfolder
)
watermark
.
main
([
'--in'
,
infolder
,
'--out'
,
watermark_outfolder
,
'--cores'
,
cores
,
'--dpi'
,
dpi
])
if
sup
==
1
:
supplements
.
main
([
'--in'
,
supinfolder
,
'--out'
,
supoutfolder
])
watermark
.
main
([
'--in'
,
supinfolder
,
'--out'
,
watermark_outfolder
,
'--cores'
,
cores
,
'--dpi'
,
dpi
])
# Encryption
enc_out
=
os
.
path
.
join
(
tmp
,
'pdfs_encrypted'
)
...
...
preparepdf.py
View file @
ead13ab4
...
...
@@ -79,7 +79,7 @@ def main(args):
continue
else
:
for
filename
in
[
f
for
f
in
filenames
if
f
.
endswith
(
".pdf"
)]:
# renames and copies PDF to outfolder
shutil
.
copy
(
os
.
path
.
join
(
dirpath
,
filename
),
os
.
path
.
join
(
outfolder
,
matnum
+
'_'
+
name
.
split
(
','
)[
0
]
+
'.pdf'
))
shutil
.
copy
(
os
.
path
.
join
(
dirpath
,
filename
),
os
.
path
.
join
(
outfolder
,
matnum
+
'_'
+
name
.
split
(
','
)[
0
]
+
'
_'
+
os
.
path
.
splitext
(
filename
)[
0
]
+
'
.pdf'
))
print
(
filename
+
' is renamed to '
+
matnum
+
'_'
+
name
.
split
(
','
)[
0
]
+
'.pdf and placed in '
+
outfolder
)
for
dirpath
,
dirnames
,
filenames
in
os
.
walk
(
os
.
path
.
join
(
extracted_folder
,
folder
)):
for
filename
in
[
f
for
f
in
filenames
if
not
f
.
endswith
(
".pdf"
)]:
...
...
supplements.py
View file @
ead13ab4
...
...
@@ -126,7 +126,7 @@ Files in output folder {} will be overwritten during this process.
if
pdf_dir
!=
""
:
# Take prefixes from pdf directory
pdf_folder
=
os
.
listdir
(
pdf_dir
)
pdf_files
=
[
_
for
_
in
pdf_folder
if
_
.
endswith
(
".pdf"
)
and
utils
.
check_matnum
(
_
[
0
:
6
])]
if
_
.
endswith
(
".pdf"
)
and
utils
.
check_matnum
(
_
.
rsplit
(
'_'
,
1
)
[
0
])]
prefixes
=
[]
for
pdf_file
in
pdf_files
:
prefix
=
os
.
path
.
splitext
(
pdf_file
)[
0
]
# take file name as prefix
...
...
utils/matnum.py
View file @
ead13ab4
...
...
@@ -32,7 +32,7 @@ def check_matnum(matnum):
Returns:
bool: valid
"""
return
len
(
matnum
)
==
6
and
matnum
.
isdigit
()
return
(
len
(
matnum
)
==
6
or
len
(
matnum
)
==
5
)
and
matnum
.
isdigit
()
def
get_matnum
(
s
):
...
...
watermark.py
View file @
ead13ab4
...
...
@@ -247,7 +247,7 @@ def main(args):
starttime
=
time
.
time
()
pdf_folder
=
os
.
listdir
(
infolder
)
pdf_files
=
[
_
for
_
in
pdf_folder
if
_
.
endswith
(
".pdf"
)
and
utils
.
check_matnum
(
_
[
0
:
6
])]
if
_
.
endswith
(
".pdf"
)
and
utils
.
check_matnum
(
_
.
rsplit
(
'_'
,
1
)
[
0
])]
print
(
"""
Available PDFs to be watermarked:
- {}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment