Closed simonw closed 2 years ago
https://developers.google.com/drive/api/v3/reference/files/export
The available export options are shown on https://developers.google.com/drive/api/v3/ref-export-formats
Those all look difficult to remember and unpleasant to type - so I'm going to assign shortcuts to just a small number of them, so you can do this:
google-drive-to-sqlite export $FILEID html
The shortcuts will be:
html
for text/html
text
for text/plain
rtf
for application/rtf
pdf
for application/pdf
word
for application/vnd.openxmlformats-officedocument.wordprocessingml.document
zip
for application/zip
epub
for application/epub+zip
For spreadsheets:
excel
for application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
csv
for text/csv
tsv
for text/tab-separated-values
And for presentations:
powerpoint
for application/vnd.openxmlformats-officedocument.presentationml.presentation
For anything else, the user can use the full content-type - e.g. for Open Office presentations:
google-drive-to-sqlite export $FILEID application/vnd.oasis.opendocument.presentation
I think this should aim to be as similar to the download
command as possible. That works like so:
Usage: google-drive-to-sqlite download [OPTIONS] FILE_IDS...
Download one or more file IDs to disk
Options:
-a, --auth FILE Path to auth.json token file
-o, --output FILE File to write to, or - for standard output
Notably, it accepts multiple file IDs, uses those as the default filename, but lets you download a single file with a custom filename using -o name-of-file
.
My initial design for export
had the conversion format as a required argument, but that doesn't look as good when you have multiple file IDs.
Actually I could still have it as a required argument, just one that comes first:
google-drive-to-sqlite export pdf $FILEID1 $FILEID2 $FILEID3
I think that looks pretty good.
First attempt at writing the help:
% google-drive-to-sqlite export --help
Usage: google-drive-to-sqlite export [OPTIONS] FORMAT FILE_IDS...
Export one or more files to the specified format.
Usage:
google-drive-to-sqlite export pdf FILE_ID_1 FILE_ID_2
The file content will be saved to a file with the name:
FILE_ID.ext
Where the extension is based on the format you specified.
Available export formats can be seen here:
https://developers.google.com/drive/api/v3/ref-export-formats
Or you can use one of the following shortcuts:
- Google Docs: html, text, rtf, pdf, word, zip, epub
- Google Sheets: excel, pdf, csv, tsv, zip
- Presentations: powerpoint, pdf, text
"zip" returns a zip file of HTML.
If you are exporting a single file you can specify a filename with -o:
google-drive-to-sqlite export zip MY_FILE_ID -o myfile.zip
Options:
-a, --auth FILE Path to auth.json token file
-o, --output FILE File to write to, or - for standard output
-s, --silent Hide progress bar and filename
--help Show this message and exit.
Needs to handle errors - this one for example:
google-drive-to-sqlite export zip 1WEtSyz5oyTTGe0Fi2NhhUX6EX7HAE-GZe3RNWHInTiE
Error: {
"error": {
"errors": [
{
"domain": "global",
"reason": "badRequest",
"message": "The requested conversion is not supported.",
"locationType": "parameter",
"location": "convertTo"
}
],
"code": 400,
"message": "The requested conversion is not supported."
}
}
So I don't have to keep figuring out how to do: