July 30

Дістати нотатки з презентації

from pptx import Presentation
import os

def extract_notes(folder_path, output_folder):
# Create output folder if it doesn't exist
if not os.path.exists(output_folder):
try:
os.makedirs(output_folder)
print(f"Created output directory: {output_folder}")
except Exception as e:
print(f"Error creating output directory: {str(e)}")
return False

pptx_files = [file for file in os.listdir(folder_path) if file.endswith('.pptx')]

if not pptx_files:
print(f"No PowerPoint files (.pptx) found in '{folder_path}'.")
return False

print(f"Processing {len(pptx_files)} PowerPoint files...")

successful_extractions = 0
for file in pptx_files:
pptx_path = os.path.join(folder_path, file)
output_file = os.path.join(output_folder, f"{os.path.splitext(file)[0]}_notes.txt")

try:
presentation = Presentation(pptx_path)
notes_found = False

with open(output_file, 'w', encoding='utf-8') as output:
output.write(f"--- Notes from {file} ---\n\n")

for i, slide in enumerate(presentation.slides):
if slide.has_notes_slide and slide.notes_slide.notes_text_frame.text:
notes_found = True
output.write(f"Slide {i+1}: {slide.notes_slide.notes_text_frame.text}\n\n")

if not notes_found:
output.write("No notes found in this presentation.\n")

print(f"Processed: {file} → {os.path.basename(output_file)}")
successful_extractions += 1

except Exception as e:
print(f"Error processing {file}: {str(e)}")

print(f"\nSuccessfully extracted notes from {successful_extractions} out of {len(pptx_files)} presentations.")
return successful_extractions > 0

def main():
print("PowerPoint Notes Extractor")
print("=========================")

folder_path = input("Enter the path to the folder containing PowerPoint files: ").strip()

# Check if folder exists
if not os.path.exists(folder_path) or not os.path.isdir(folder_path):
print(f"Error: The folder '{folder_path}' does not exist or is not a directory.")
return

output_folder = input("Enter the path for the output folder (default: 'extracted_notes'): ").strip()

# If user provided no path, use a default folder name
if not output_folder:
output_folder = "extracted_notes"

print(f"\nExtracting notes to folder: {output_folder}")
success = extract_notes(folder_path, output_folder)

if success:
print(f"\nNotes successfully extracted to folder: {output_folder}")
print(f"Each presentation's notes are saved in a separate file.")

if __name__ == "__main__":
main()