Download, back up, and upload Google Docs files
Aug 26, '09 07:30:03AM
Contributed by: bluehz
You can download, back up, and upload documents from your Google Docs account using a little Terminal magic.
Prerequisites:
- gdata-python-client 2.0.1 - download page
- gdatacopier 1.0.2 - download page
Installation:
- Download the prerequisites. Decompress each of the downloads.
- Install gdata-python-client:
$ cd gdata-2.0.1<br>
$ sudo python setup.py install
Patch:
The current gdatacopier download has a small bug in it, and it needs to be patched to work properly. Open the file gdatacopier.py in the app's folder, and locate line 555. On that line, change this...
item_list.append({'title': entry.title.text.encode('UTF-8'),
...to this...
item_list.append({'title': entry.title.text,
Save the file and quit the editor.
Usage:
By default, gdatacopier will download your spreadsheets and text documents in the OpenOffice format (.ods and .odt, respectively). TextEdit does a pretty good job of opening the text (.odt) documents, but I was unable to find anything free that could open the spreadsheet (.ods) documents, so you may want to specify a specific format when downloading your documents.
Variables
- $DIR = local download location
- $USERNAME = Google email (e.g. someone@gmail.com)
- $GOOGLEID = Google docs id number. You can find the document's Google ID by using the list- commands below. Make sure to copy only the Google ID from the listing -- not the date or other data. Also make sure to enclose the Google ID in quotes in your command.
Examples:
- Display gdatacopier help: ./gdoc-cp.py --help
- Back up all Google Docs in OpenOffice format: ./gdoc-cp.py --username someone@gmail.com --export default --google-id all --local $DIR
- Back up all Google Docs spreadsheets in Excel format: ./gdoc-cp.py --username $USERNAME --export xls --google-id spreadsheets --local $DIR
- Back up all Google Docs Text in Rich Text format (retains most formatting): ./gdoc-cp.py --username $USERNAME --export rtf --google-id documents --local $DIR
- Back up all Google Docs in PDF Format: ./gdoc-cp.py --username $USERNAME --export pdf --google-id all --local $DIR
- List all Google Docs: ./gdoc-cp.py --username $USERNAME --list-all
- List all Google Docs spreadsheets: ./gdoc-cp.py --username $USERNAME --list-sheets
- List all Google Docs text documents: ./gdoc-cp.py --username $USERNAME --list-docs
- Find a specific Google Doc by title: ./gdoc-cp.py --username $USERNAME -p $PASSWORD --list-all | grep Casserole
- Download a specific text document in TextEdit (rtf) format: ./gdoc-cp.py --username $USERNAME --export rtf --google-id "$GOOGLEID" --local "OUTPUT_FILENAME.rtf"
- Download a specific spreadsheet document in Excel (xls) format: ./gdoc-cp.py --username $USERNAME --export xls --google-id "$GOOGLEID" --local "OUTPUT_FILENAME.xls"
- Download a specific document in PDF format: ./gdoc-cp.py --username $USERNAME --export pdf --google-id "$GOOGLEID" --local "OUTPUT_FILENAME.pdf"
- Upload a document to Google Docs (rtf, txt, xls, doc): ./gdoc-cp.py --username $USERNAME --import --local "INPUT_FILENAME" --title "OPTIONAL_TITLE"
Notes:
- A password can be hardcoded into the command if desired.
- The current version of gdatacopier (1.0.2) is unable to upload all the file types supported by Google Docs (including PDF, html, docx, and possibly others -- that's all I tested).
- gdatacopier-1.0.3 in the repository appears to offer support for presentations and some other options including folders (aka tags). If you want to play around with it you can get it here. (The code must be patched as above, plus also patch line 289:
download_document(document_id, file_format, local_path, write_metadata) -- change that to download_item(document_id, file_format, local_path, write_metadata).)
- A future v2.0 is in the works, hopefully soon.
- Maybe a crafty AppleScript Studio programmer could write a GUI for all this.
[robg adds: I haven't tested this one.]
Comments (2)
Mac OS X Hints
http://hints.macworld.com/article.php?story=20090818101546358