simonw / google-drive-to-sqlite

Create a SQLite database containing metadata from Google Drive
https://datasette.io/tools/google-drive-to-sqlite
Apache License 2.0
152 stars 13 forks source link

google-drive-to-sqlite export command (like download but does exports) #21

Closed simonw closed 2 years ago

simonw commented 2 years ago

So I don't have to keep figuring out how to do:

google-drive-to-sqlite get 'https://www.googleapis.com/drive/v3/files/1WEtSyz5oyTTGe0Fi2NhhUX6EX7HAE-GZe3RNWHInTiE/export?mimeType=text/plain'
simonw commented 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

image

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:

For spreadsheets:

And for presentations:

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
simonw commented 2 years ago

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.

simonw commented 2 years ago

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.
simonw commented 2 years ago

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."
 }
}