From 15b12ee16032c917d076f56fa72d4ae28058fd3c Mon Sep 17 00:00:00 2001 From: kodster28 Date: Thu, 4 Apr 2019 12:47:08 -0500 Subject: [PATCH] Add files via upload --- Abstract_Refresh.py | 105 ++++++++++++++++++++++++++++++++++++++++ LMS_file_creator.py | 69 ++++++++++++++++++++++++++ Product_Name_Updater.py | 63 ++++++++++++++++++++++++ stats_checker.py | 10 ++-- stats_updater.py | 10 ++-- 5 files changed, 247 insertions(+), 10 deletions(-) create mode 100644 Abstract_Refresh.py create mode 100644 LMS_file_creator.py create mode 100644 Product_Name_Updater.py diff --git a/Abstract_Refresh.py b/Abstract_Refresh.py new file mode 100644 index 0000000..faa7edc --- /dev/null +++ b/Abstract_Refresh.py @@ -0,0 +1,105 @@ +import win32com.client as win +import re + +word = win.gencache.EnsureDispatch("Word.Application") +word.Visible = True +Document = word.Documents.Open("c://users//kody.jackson//desktop//RENXT_FUN_Fundraising_Abstract_120518.docx") +header = Document.Sections.Item(1).Headers(1) + +document_information = [['PRODUCT NAME', ''], + ['COURSE NAME', ''], + ['COURSE TYPE', ''], + ['MODALITY', ''], + ['DURATION', ''], + ['DELIVERY METHOD', ''], + ['PREREQUISITES', ''], + ['COURSE OVERVIEW', ''], + ['TARGET AUDIENCE', ''], + ['LEARNING OBJECTIVES', ''], + ['VIEW ADDITIONAL INFORMATION', '']] + + + + +for x in range (1, header.Shapes.Count + 1): + try: + if header.Shapes(x).TextFrame.TextRange.Font.Bold: + document_information[0][1] = header.Shapes(x).TextFrame.TextRange.Text.strip() + + else: + document_information[1][1] = header.Shapes(x).TextFrame.TextRange.Text.strip() + except: + print () + +text = Document.Range().Text + + +for y in range (2, 10): + nameRegex = re.compile(document_information[y][0]+ '(.*?)' + document_information[y + 1][0]) + document_information[y][1] = nameRegex.search(text).group(1).strip() + + + +##with open('C:\\Users\\kody.jackson\\Desktop\\' + document_information[0][1] + '_' + document_information[1][1] + '.txt', 'w') as document: +## for z in range(0, 10): +## document.write('%s\n' % document_information[z]) + + + +Document.Close() + +Document = word.Documents.Open('C:\\Users\\kody.jackson\\Desktop\\Old_Abstract.dotx') +##Document = word.Documents.SaveAs('C:\\Users\\kody.jackson\\Desktop\\' + document_information[0][1] + '_' + document_information[1][1] + '.docx') + +##find and replace through the body of the document + +for z in range (0, len(document_information)): + if ' ' in document_information[z][0]: + document_information[z][0] = document_information[z][0].lower().capitalize().replace(' ', '_') + else: + document_information[z][0] = '_' + document_information[z][0].lower() + '_' + + +for c in range (2, len(document_information) - 1): + if len(document_information[c][1]) < 255: + find = word.Selection.Find + find.ClearFormatting() + find.Replacement.ClearFormatting() + find.Text = document_information[c][0] + find.Replacement.Text = document_information[c][1] + find.Forward = True + find.Wrap = win.constants.wdFindContinue + find.Execute(Replace=win.constants.wdReplaceAll) + + else: + start = 0 + stop = 200 + step = 200 + length_to_go = True + while length_to_go: + + if len(document_information[c][1]) < start: + find = word.Selection.Find + find.ClearFormatting() + find.Replacement.ClearFormatting() + find.Text = document_information[c][0] + find.Replacement.Text = '' + find.Forward = True + find.Wrap = win.constants.wdFindContinue + find.Execute(Replace=win.constants.wdReplaceAll) + length_to_go = False + + else: + find = word.Selection.Find + find.ClearFormatting() + find.Replacement.ClearFormatting() + find.Text = document_information[c][0] + find.Replacement.Text = document_information[c][1][start:stop] + document_information[c][0] + find.Forward = True + find.Wrap = win.constants.wdFindContinue + find.Execute(Replace=win.constants.wdReplaceAll) + start += step + stop += step + + +##word.Quit() diff --git a/LMS_file_creator.py b/LMS_file_creator.py new file mode 100644 index 0000000..d2074c3 --- /dev/null +++ b/LMS_file_creator.py @@ -0,0 +1,69 @@ +##For saving files in the new LMS format + +import os, shutil, win32com.client + +#define the function + +def create_LMS_folder (excel_row): + + ##declare variables, copy, rename, and add the target folder to the CSOD + course_name = sheet.Cells(excel_row, 1).Value + course_file_name = sheet.Cells(excel_row, 2).Value + product_abbreviation = sheet.Cells(excel_row, 3).Value + email_address = sheet.Cells(excel_row, 4).Value + new_folder_path = os.path.join(folder_path, product_abbreviation, course_file_name) + + shutil.copytree(os.path.join(folder_path, "Generic_Class_Resources"), new_folder_path) + + ##rename the individual files + os.rename(os.path.join(new_folder_path, "Generic_Abstract.pdf"), os.path.join(new_folder_path, course_file_name + "_Abstract.pdf")) + os.rename(os.path.join(new_folder_path, "Generic_Handout.pdf"), os.path.join(new_folder_path, course_file_name + "_Handout.pdf")) + os.rename(os.path.join(new_folder_path, "Generic_Resources.docx"), os.path.join(new_folder_path, course_file_name + "_Resources.docx")) + resource_file = os.path.join(new_folder_path, course_file_name + "_Resources") + + + ##open the word file and perform tasks + word = win32com.client.gencache.EnsureDispatch("Word.Application") + document = word.Documents.Open(resource_file + ".docx") + + ##find and replace course name + find = word.Selection.Find + find.ClearFormatting() + find.Replacement.ClearFormatting() + find.Text = "Generic Course Name" + find.Replacement.Text = course_name + find.Forward = True + find.Wrap = win32com.client.constants.wdFindContinue + find.Execute(Replace=win32com.client.constants.wdReplaceAll) + + ##add hyperlink. Make sure that begins with http + hyperlink = "https://www.blackbaud.com/files/training/jobaids/CSOD/" + product_abbreviation + '/' + course_file_name + '/' + course_file_name + '_Handout.pdf' + document.Hyperlinks.Add(document.InlineShapes(3).Range, hyperlink) + + ##save and save as PDF + document.Save() + document.ExportAsFixedFormat(os.path.join(resource_file + '.pdf'), 17) + document.Close() + word.Quit() + + return; + + +##call the function for all values in an excel file +folder_path = "C:\\Users\\kody.jackson\\Desktop\\CSOD_test" +excel_file = os.path.join(folder_path, "LMS_file_input.xlsx") + +xl = win32com.client.Dispatch("Excel.Application") +xl.Visible = False +workbook = xl.Workbooks.Open(excel_file) +sheet = workbook.ActiveSheet + + +row = 2 +while sheet.Cells(row, 1).Value != None: + create_LMS_folder(row) + row += 1 + +workbook.Save() +workbook.Close() +xl.Quit() diff --git a/Product_Name_Updater.py b/Product_Name_Updater.py new file mode 100644 index 0000000..3775d30 --- /dev/null +++ b/Product_Name_Updater.py @@ -0,0 +1,63 @@ +import os +import win32com.client, sys +folder_path = 'C:\\Users\\kody.jackson\\Desktop\\python_test' + +Application = win32com.client.Dispatch("PowerPoint.Application") +Application.Visible = True + +for item in os.listdir(folder_path): + if ".pptx" in item: + filename = os.path.join(folder_path, item) + + + Presentation = Application.Presentations.Open(filename) + + + nameList = ["database view", "Database view", "Database View"] + notesCount = 0 + slideCount = 0 + + for x in range(1, Presentation.Slides.Count + 1): + + for shape in range(1, Presentation.Slides(x).Shapes.Count + 1): + + if Presentation.Slides(x).Shapes(shape).HasTextFrame or "TextBox" in Presentation.Slides(x).Shapes(shape).Name: + + if any(word in Presentation.Slides(x).Shapes(shape).TextFrame.TextRange.Text for word in nameList): + slideCount += 1 + Presentation.Slides(x).Comments.Add(Left= 12, Top= 12, Author= "Kody", AuthorInitials= "KJ", Text= "This slide has the phrase on its slide face") + + if "Group" in Presentation.Slides(x).Shapes(shape).Name: + + for items in range(1, Presentation.Slides(x).Shapes(shape).GroupItems.Count + 1): + + if Presentation.Slides(x).Shapes(shape).GroupItems(items).HasTextFrame or "TextBox" in Presentation.Slides(x).Shapes(shape).GroupItems(items).Name: + if any(word in Presentation.Slides(x).Shapes(shape).GroupItems(items).TextFrame.TextRange.Text for word in nameList): + slideCount += 1 + Presentation.Slides(x).Comments.Add(Left= 12, Top= 12, Author= "Kody", AuthorInitials= "KJ", Text= "This slide has the phrase on its slide face") + + for shape in range(1, Presentation.Slides(x).NotesPage.Shapes.Count + 1): + if Presentation.Slides(x).NotesPage.Shapes(shape).HasTextFrame: + if any(word in Presentation.Slides(x).NotesPage.Shapes(shape).TextFrame.TextRange.Text for word in nameList): + notesCount += 1 + Presentation.Slides(x).Comments.Add(Left= 12, Top= 12, Author= "Kody", AuthorInitials= "KJ", Text= "The slide text has been touched") + while any(word in Presentation.Slides(x).NotesPage.Shapes(shape).TextFrame.TextRange.Text for word in nameList): + Presentation.Slides(x).NotesPage.Shapes(shape).TextFrame.TextRange.Replace(FindWhat= "database view", ReplaceWhat= "advanced administration view", MatchCase = True) + Presentation.Slides(x).NotesPage.Shapes(shape).TextFrame.TextRange.Replace(FindWhat= "Database view", ReplaceWhat= "Advanced administration view", MatchCase = True) + Presentation.Slides(x).NotesPage.Shapes(shape).TextFrame.TextRange.Replace(FindWhat= "Database View", ReplaceWhat= "Advanced Administration View", MatchCase = True) + + + + Presentation.Slides(1).Comments.Add(Left= 12, Top= 12, Author= "Kody", AuthorInitials= "KJ", Text= "The program has addressed notes issues on " + str(notesCount) + ' number of slides.') + + Presentation.Slides(1).Comments.Add(Left= 12, Top= 12, Author= "Kody", AuthorInitials= "KJ", Text= "The program has called out " + str(slideCount) + ' issues in the slide face.') + + if notesCount > 0 or slideCount > 0: + Presentation.SaveAs(os.path.join(folder_path, 'Items_Found_Needs_Verification', item)) + else: + Presentation.SaveAs(os.path.join(folder_path, 'None_Found', item)) + +Application = win32com.client.Dispatch("PowerPoint.Application") +Application.Quit() + + diff --git a/stats_checker.py b/stats_checker.py index 2237cdb..450dcf5 100644 --- a/stats_checker.py +++ b/stats_checker.py @@ -1,12 +1,12 @@ -##testing - import win32com.client, sys +from LMS_file_creator_Excel import create_LMS_folder filename = "C:\\Users\\kody.jackson\\Documents\\Stats_test\\Stat_test_2.pptx" Application = win32com.client.Dispatch("PowerPoint.Application") Application.Visible = True + Presentation = Application.Presentations.Open(filename) sourceCount = 0 slideList = [] @@ -14,14 +14,14 @@ for x in range(1, Presentation.Slides.Count + 1): - + for shape in range(1, Presentation.Slides(x).Shapes.Count + 1): - + if Presentation.Slides(x).Shapes(shape).HasTextFrame or "TextBox" in Presentation.Slides(x).Shapes(shape).Name: ##add in try and except blocks - + if any(word in Presentation.Slides(x).Shapes(shape).TextFrame.TextRange.Text for word in sourceList): sourceCount += 1 slideList.append(Presentation.Slides(x).SlideNumber) diff --git a/stats_updater.py b/stats_updater.py index 521bb29..0d064da 100644 --- a/stats_updater.py +++ b/stats_updater.py @@ -21,11 +21,11 @@ if old_source in Slides(x).Shapes("Source_Text").TextFrame.TextRange.Text: print("Got the slide") - + for shape in range(1, Slides(x).Shapes.Count + 1): print("This is shape " + Slides(x).Shapes(shape).Name) - + if Slides(x).Shapes(shape).HasTextFrame or "TextBox" in Slides(x).Shapes(shape).Name: @@ -40,10 +40,10 @@ Slides(x).Shapes(shape).TextFrame.TextRange.Replace(FindWhat= key, ReplaceWhat= stats_dict[key], MatchCase = True) Slides(x).Comments.Add(Left= 12, Top= 12, Author= "Kody", AuthorInitials= "KJ", Text= "I replaced a stat here") print("is this working?") - - + + except: @@ -51,7 +51,7 @@ print("This slide doesn't have that value") - + ##Presentation.Save() ##Presentation.Close() ##