Commit ead13ab4 authored by Amrita's avatar Amrita
Browse files

handles 5digit mn+modify batch for ESiss3

parent 70d25c09
......@@ -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')
......
......@@ -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")]:
......
......@@ -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
......
......@@ -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):
......
......@@ -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:
- {}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment