-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
247 additions
and
10 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
|
||
|
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
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