import os, io, json from google.oauth2.credentials import Credentials from googleapiclient.discovery import build from googleapiclient.http import MediaIoBaseDownload import pymupdf token_path = os.path.expanduser("~/.hermes/profiles/reviewer/google_token.json") with open(token_path) as f: creds = Credentials.from_authorized_user_info(json.load(f)) docs_service = build("docs", "v1", credentials=creds) drive_service = build("drive", "v3", credentials=creds) doc_id = "1sjTe7Im51CY2Tl0SNQrm8xmO7bYweMkq44E0WXaxs1I" doc = docs_service.documents().get(documentId=doc_id).execute() body = doc.get("body", {}) content = body.get("content", []) el = content[2] table = el["table"] print("Table cell 0 content:") for c in table["tableRows"][0]["tableCells"][0]["content"]: if "paragraph" in c: p_txt = "".join([e.get("textRun", {}).get("content", "") for e in c["paragraph"]["elements"] if "textRun" in e]) print(" Cell 0 P:", repr(p_txt)) print("\nTable cell 1 content:") for c in table["tableRows"][0]["tableCells"][1]["content"]: if "paragraph" in c: p_txt = "".join([e.get("textRun", {}).get("content", "") for e in c["paragraph"]["elements"] if "textRun" in e]) print(" Cell 1 P:", repr(p_txt)) # Let's inspect borders of Table cell 0 print("\nCell 0 style:", json.dumps(table["tableRows"][0]["tableCells"][0].get("tableCellStyle", {}), indent=2))