Last active
December 14, 2018 04:51
-
-
Save avivo/19322731766480b72208a8db434bf015 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pptx import Presentation | |
import argparse | |
import re | |
from termcolor import colored as c | |
# Bash one liner version to get a similar thing: | |
# unzip -p presenation.pptx | sed -e 's/<[^>]*>//g' | tr '\r' '\n' | egrep --colour '[0-9]*$' | |
def parse_args(): | |
parser = argparse.ArgumentParser(description='Analyze powerpoint') | |
parser.add_argument('pptx', | |
type=argparse.FileType('r'), | |
help='Powerpoint file to be analyzed') | |
parser.add_argument('-c', | |
action='store_true', | |
help='Count each note length & cumalitive') | |
parser.add_argument('-b', | |
type=int, | |
default=1, | |
help='Begin at slide b') | |
parser.add_argument('-e', | |
type=int, | |
help='End at slide e') | |
parser.add_argument('-d', | |
action='store_false', | |
default=True, | |
help='Skip divider') | |
parser.add_argument('-s', | |
action='store_false', | |
default=True, | |
help='Skip slides') | |
parser.add_argument('-n', | |
action='store_false', | |
default=True, | |
help='Skip notes') | |
parser.add_argument('-l', | |
action='store_false', | |
help='Skip total notes length') | |
return parser.parse_args() | |
def strip_extra(s): | |
return re.sub(r'\n$', '', re.sub(r'\n\n', '\n', s, re.MULTILINE)) | |
def count(s): | |
c = len(re.findall(r'\w+', s)) | |
return round(c / 140.0, 1) | |
if __name__ == "__main__": | |
args = parse_args() | |
p = Presentation(args.pptx) | |
total = 0 | |
for relative_index, s in enumerate(list(p.slides)[args.b - 1:]): | |
i = relative_index + args.b # i is 1 indexed slide number (like in ppt) | |
if args.d: | |
print c("------ " + str(i) + " ------", 'red') | |
slide_text = ''.join([h.text for h in s.shapes if hasattr(h, 'text')]) | |
if args.s: | |
print c(strip_extra(slide_text), 'blue') | |
notes_text = s.notes_slide.notes_text_frame.text | |
if args.n: | |
print strip_extra(notes_text) | |
if args.c: | |
notes_length = count(notes_text) | |
total = total + notes_length | |
print c(str(notes_length), 'green'), " cumal:", c(str(total), 'green') | |
if args.e and args.e == i: | |
break | |
if args.l: | |
all_notes_text = [s.notes_slide.notes_text_frame.text for s in p.slides] | |
print 'Total for deck:', c(count(' '.join(all_notes_text)), 'green') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment