Package: drive-files-gen
Drive files generatorTool to generate folders and documents on Google Drive from a JSON file.JSON file treeThe JSON file describes the file tree you want to create on Google Drive.An example will help you understand the structure of it.{"my-drive":{"docs":["My Google Docs"],"sheets":3,"folders":{"ZORRO":{"forms":1,"sites":["Google Site #1","Google Site #2"],"folders":{"my last folder":{}}}}}}The outter object must have a single entry. The key is the ID of the folder where you want to create the file tree
or the special valuemy-driveif you want it to be the root of your Drive. A shared drive ID can be passed too.Inside a folder, you can specify the different Google Drive elements you want to create. Either documents from the
the list, or the special "folders" entry if you want to create subfolders.A folder is identified by its name (= JSON key). Exception for the root element which ismy-driveor an existing
Google Drive ID.To specify which Google Docs, Sheets, Sites (and so on) you want to create, you can either tell how many you want
and they will have a timestamp for name ("docs": 3will create 3 Google Docs - not possible for folders at the moment)
or you can specify a list of names ("docs": ["one", "two", "three"]).If you want to create an empty folder, just add an entry with an empty dict ("my last folder": {})Types of Google Drive filesHere are the types of files you can create. The left-hand side is what you put in your JSON file,
the right-hand side is the corresponding mime type in Google Drive.{"docs":"application/vnd.google-apps.document","drawings":"application/vnd.google-apps.drawing","forms":"application/vnd.google-apps.form","slides":"application/vnd.google-apps.presentation","scripts":"application/vnd.google-apps.script","sites":"application/vnd.google-apps.site","sheets":"application/vnd.google-apps.spreadsheet",}CredentialsAt the moment, the script is not packaged nor published as an app. So you have to create your own GCP Oauth
client ID for installed app (this procedure).Download the JSON file and pass it to the command line.The script will ask for permission to write in Google Drive. After the scope authorization process is done, it
will save your refresh token + access token into a file if (and only if) you have passed--store-credswith a file
path to the command line.
Otherwise it will ask your permission at each run.Run the scriptusage: drive_files_gen.py [-h] [--store-creds STORE_CREDS] client_id_file json_file

Generate Google Drive folders and documents from a JSON file.

positional arguments:
  client_id_file        the client id JSON file, downloaded from GCP
  json_file             the Drive file tree, in JSON format

optional arguments:
  -h, --help            show this help message and exit
  --store-creds STORE_CREDS
                        if you want to store your creds (refresh + access token) on your filesystem, give it a file pathTest the scriptI've made a bit of unit testing withpytest. It requires to have both a JSON Oauth client file and
a valid JSON credentials file (with the refresh token + access token).
You will see intest_main.pythat I reference atest_configpackage, which is where I store the path to JSON files.To test it, simply runpytest