This Python script fetches content from Google Docs using the Google Docs API and converts it to structured pages using Google's Gemini API.
-
Install dependencies:
pip install -r requirements.txt
-
Set up Google Docs API:
- Go to the Google Cloud Console
- Create a new project
- Enable the Google Docs API
- Create OAuth 2.0 credentials (Desktop application)
- Download the credentials JSON file and save it as
credentials.jsonin the project directory
-
Set up Gemini API:
- Go to the Google AI Studio
- Create an API key
- Create a
.envfile in the project directory with the following content:GEMINI_API_KEY=your_api_key_here
Run the script with the following command:
python gemini_doc_fetch.py --doc_id YOUR_DOCUMENT_ID --output output.htmlParameters:
--doc_id: The ID of the Google Document (required)- You can find this in the URL of your Google Doc:
https://docs.google.com/document/d/YOUR_DOCUMENT_ID/edit
- You can find this in the URL of your Google Doc:
--output: Path to save the HTML output (optional)--credentials: Path to the credentials.json file (default: credentials.json)
python gemini_doc_fetch.py --doc_id 1AbCdEfGhIjKlMnOpQrStUvWxYz12345 --output blog_post.html- Authenticates with Google Docs API
- Fetches document content
- Uses Gemini AI to convert the document to structured HTML
- Saves the HTML output to a file or prints it to the console
- The first time you run the script, it will open a browser window to authenticate with Google
- The authentication token will be saved for future use
- The Gemini API is used to intelligently convert the document content to HTML