import argparse, os, sys, glob
from PyPDF2 import PdfFileReader

if __name__ == "__main__":

	p = argparse.ArgumentParser(description='Mailinglists are dead. Long live mailinglists!')
	p.add_argument('dir', metavar="dir", help="pdf dir")

	args = p.parse_args()

	if not os.path.isdir(args.dir):
		sys.exit(l + ' is not a valid directory. Aborting.')

	files = [f for f in glob.glob(os.path.join(args.dir, "*.pdf"))]

	total_pages = 0
	for f in files:		
		with open(f) as fp:
			p = PdfFileReader(f)
			np = p.getNumPages()
			print(f + " - nbr. pages: " + str(np))
			total_pages += np

	print(". . . . \n Total pages: " + str(total_pages))
