Package: dlgsheet
Python script for downloading sheets from Google Sheets as JSON filesRequirementsNOTEThis information is taken from the google-api documentation for Python
from:https://github.com/googleapis/google-api-python-client/blob/master/docs/oauth-server.mdCreate a service accountService accounts allow you to perform server to server, app-level authentication using a robot account. You will create a service account, download a keyfile, and use that to authenticate to Google APIs. To create a service account:Go to theCreate Service Account Key pageClick the buttonCreate new service accountEnter the service account name and the corresponding id.Add the additional information regarding users and project permissions
(optional)Create the service account.Once it is created you should create a keyfile, then follow the next steps:Enter to the newly created service accountGo to theKeystabClick the buttonAdd keyand selectJSON.Save the service account credential file somewhere safe, and do not check this file into source control!Add permissions to the documentIf you want to perform operations in a private file, you should add the service
mail (e.g.service-name@project-name.iam.gserviceaccount.com) to the list of
shared users in your document.You can read this reference which explains this specific requirement:https://github.com/juampynr/google-spreadsheet-readerInstallationTo install this package you must build and install following the procedure
suggested for setuptoolshttps://setuptools.readthedocs.io/en/latest/userguide/quickstart.html.pip install --upgrade setuptools
python -m build .
python install .You can also use the scrip from the current source by:pip install -r requirements.txtHow to useThe script could be used installed in your local environment, or directly from the
location of the package source.If you have installed it, the command name isdlgsheetand admits the next
options:dlgsheet [options]Options:-h, --helpShow this help message and exit-l LOGLEVEL, --log-level=LOGLEVELSet log level. Available options: critical, error, warning, info, debug-c FILE, --credentials-file=FILESet credentials file name-o FILE, --output-file=FILESave to output file-d FOLDEr, --output-folder=FOLDERSave to output folder-s SPREADSHEETID, --spreadsheet-id=SPREADSHEETIDSet google spreadsheet id to write on-t SHEETNAME, --sheetname=SHEETNAMESet google sheetname to write on-k KEY_INDEX, --key-index=KEY_INDEXSet key index to generate object related to it-K, --use-keys-tableUse keys table in spreadsheet-T KEYS_TABLE, --keys-table=KEYS_TABLEKeys table name in spreadsheet. Default '_keys'-n TABLENAME_COLUMN, --tablename-column=TABLENAME_COLUMNTablename column in keys table. Default 'tablename'-i KEY_INDEX_COLUMN, --key-index-column=KEY_INDEX_COLUMNKey index column in keys table. Default 'key_index'-B BLACKLIST, --blacklist=BLACKLISTList of tables that won't be considered, separated by commas. Default '_keys'From these options, providing the--spreadsheet-idis mandatory either via the
command line or via an environmental variableGOOGLE_SPREADSHEET_ID.Then, it is required also that you provide the key file downloaded from the Google
service account, explained above. It should be defined via the option--credentials-file, otherwise it will use the default filenamekey.json,
which should be located in the current path where the script is executed.There are some environment which may be employed to define some options:VariableDefaultGOOGLE_SPREADSHEET_ID(none)GOOGLE_AUTH_FILENAMEkey.jsonYou have two options to use this software:Downloading all the sheets. When using with no arguments, it employs the
default folder nameoutputand saves the sheets in JSON files under this
folder with the name<sheetname>.json.Downloading single sheet. Whensheetnameis defined, then uses this
mode downloading only the specified sheet.In addition to this, when the output filename is not defined via--output, the default filename used is a construction of:output/<sheetname>.json, wheresheetnameis the sheet name in the Google
spreadsheet. Similarly, when the output folder is not defined via--output-folder, the default folder name isoutputunder the current
directory where the script is launched.In case you are using the script from the source folder, you can call it via:python -m dlgsheet [options]Where[options]are the options described above.In case you have installed, it automatically installs a script to the system
path, so you can call as:dlgsheet [options]Use casesSingle sheetdlgsheet --sheetname SHEETNAMEUsing in a spreadsheet which has aSHEETNAMEsheet  with the following
values:key_1key_2key_3value_1_1value_1_2value_1_3value_2_1value_2_2value_2_3value_3_1value_3_2value_3_3The results will be a file with the nameSHEETNAME.jsonin the folderoutput, with the following info:[
    {
        "key_1": "value_1_1",
        "key_2": "value_1_2",
        "key_3": "value_1_3"
    },
    {
        "key_1": "value_2_1",
        "key_2": "value_2_2",
        "key_3": "value_2_3"
    },
    {
        "key_1": "value_3_1",
        "key_2": "value_3_2",
        "key_3": "value_3_3"
    }
]Single sheet with key indexdlgsheet --sheetname SHEETNAME --key-index 0Using in a spreadsheet which has aSHEETNAMEsheet  with the following
values:key_1key_2key_3value_1_1value_1_2value_1_3value_2_1value_2_2value_2_3value_3_1value_3_2value_3_3The results will be a file with the nameSHEETNAME.jsonin the folderoutput, with the following info:{
    "value_1_1": {
        "key_2": "value_1_2",
        "key_3": "value_1_3"
    },
    "value_2_1": {
        "key_2": "value_2_2",
        "key_3": "value_2_3"
    },
    "value_3_1": {
        "key_2": "value_3_2",
        "key_3": "value_3_3"
    }
}All sheets in spreadsheetdlgsheetIt saves all the sheets except those in the blacklist, by default '_keys'. The
data is saved to the folderoutputwith one file for each sheet.All sheets in spreadsheet with key indexdlgsheet  --key-index 0It saves all the sheets except those in the blacklist, by default '_keys'. The
data is saved to the folderoutputwith one file for each sheet, but in this
case uses the column index 0 to obtain the object for all the sheets. If the
index is out of the range in a sheet, the generation is skipped in this case.All sheets in spreadsheet with a sheet configurationdlgsheet  --use-keys-tableIn this case, it uses a keys' table (by default with_keysname) where it has
the information about the sheets that should be saved related to a specified
key and the key index in the columns for each sheet.The keys' table must have the following structure:tablenamekey_indexsheet_10sheet_30sheet_50Wheresheet_xrepresents the sheet name in the spreadsheet that will use a
key index and the values in thekey_indexcolumn is the position of the
column that will be used as keys for the generated object.If the spreadsheet has other sheets that are not present in thetablenamecolumn, then the generation is without considering an index.LicenseCopyright 2021 Luighi Viton-ZorrillaLicensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.