Created
November 8, 2024 05:16
-
-
Save e96031413/7dea85753474b5a32723e2cf558d4b53 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
import requests | |
import os | |
from urllib.parse import urlparse | |
def convert_to_pdf_url(presentation_url): | |
# Remove any trailing parameters or /edit | |
base_url = presentation_url.split('/edit')[0].split('?')[0] | |
# Add /export/pdf to the end | |
return f"{base_url}/export/pdf" | |
def download_presentations(urls, output_folder="downloaded_presentations"): | |
# Create output folder if it doesn't exist | |
if not os.path.exists(output_folder): | |
os.makedirs(output_folder) | |
for i, url in enumerate(urls, 1): | |
try: | |
# Convert URL to PDF download URL | |
pdf_url = convert_to_pdf_url(url) | |
# Extract presentation ID for filename | |
presentation_id = urlparse(url).path.split('/')[-1] | |
filename = f"presentation_{presentation_id}.pdf" | |
filepath = os.path.join(output_folder, filename) | |
# Download the PDF | |
print(f"Downloading {i}/{len(urls)}: {filename}") | |
response = requests.get(pdf_url) | |
if response.status_code == 200: | |
with open(filepath, 'wb') as f: | |
f.write(response.content) | |
print(f"Successfully downloaded: {filename}") | |
else: | |
print(f"Failed to download: {filename}") | |
except Exception as e: | |
print(f"Error downloading {url}: {str(e)}") | |
# Your list of URLs | |
urls = [ | |
"https://docs.google.com/presentation/d/XXXXXXXXXXXXXXXXXXX", | |
] | |
# Download the presentations | |
download_presentations(urls) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment