Create monthly PPT reports
from datetime import date | |
from string import Template | |
from pptx import Presentation | |
# this file must exist | |
template = 'x_Academic Apps-y.pptx' | |
prs = Presentation(template) | |
fy = ['2018', '2019'] | |
h = 'Academic Applications\n[y] Accomplishments & Statistics' | |
ht = Template('$month Accomplishments & Statistics') | |
fn = Template('$monthNum Academic Apps $month $year.pptx') | |
month_to_year = dict({ | |
'July': fy[0], | |
'August': fy[0], | |
'September': fy[0], | |
'October': fy[0], | |
'November': fy[0], | |
'December': fy[0], | |
'January': fy[1], | |
'February': fy[1], | |
'March': fy[1], | |
'April': fy[1], | |
'May': fy[1], | |
'June': fy[1] | |
}) | |
fy_cal = dict({ | |
"1" : date(int(fy[0]),7,1), | |
"2": date(int(fy[0]), 8, 1), | |
"3": date(int(fy[0]), 9, 1), | |
"4": date(int(fy[0]), 10, 1), | |
"5": date(int(fy[0]), 11, 1), | |
"6": date(int(fy[0]), 12, 1), | |
"7" : date(int(fy[1]),1,1), | |
"8": date(int(fy[1]), 2, 1), | |
"9": date(int(fy[1]), 3, 1), | |
"10": date(int(fy[1]), 4, 1), | |
"11": date(int(fy[1]), 5, 1), | |
"12": date(int(fy[1]), 6, 1) | |
}) | |
for month_number, date in fy_cal.items(): | |
month_name = date.strftime("%B") | |
year = month_to_year[month_name] | |
file_name = fn.substitute(monthNum=month_number,month=month_name, year=year) | |
print month_number, month_name, year | |
print file_name | |
prs = Presentation(template) | |
text_runs = [] | |
for slide in prs.slides: | |
for shape in slide.shapes: | |
if not shape.has_text_frame: | |
continue | |
#text_runs.append(shape.name) | |
for paragraph in shape.text_frame.paragraphs: | |
print paragraph.text | |
if paragraph.text == u'Academic Applications[x] Accomplishments & Statistics': | |
t = Template('Academic Applications\n$month Accomplishments & Statistics') | |
shape.text = t.substitute(month=month_name) | |
print 'edit' | |
print shape.text | |
if paragraph.text == u'[x]': | |
shape.text_frame.clear() | |
p = shape.text_frame.paragraphs[0] | |
run = p.add_run() | |
t = Template('$month\nHighlight') | |
run.text = t.substitute(month=month_name) | |
shape.text = t.substitute(month=month_name) | |
print 'edit' | |
print shape.text | |
prs.save(file_name) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment