A very basic example of how to use gspread to pull data from a google sheet and populate a jinja template.
This code uses google bot credentials stored in ~/.config/gspread/service_account.json
to open a google sheet called New Switches. For each tab it generates access port configuration for an IOS device based on a jinja template and saves it as a file based on the name of the tab.
- Copy the example spreadsheet. Make sure to preserve the name of the spreadsheet (or update the python code in this repo so that it points to the new spreadsheet name).
- Follow gspread instructions for creating a bot service account and sharing it with the sheet above.
- Note: This method sets up an account for a "bot" as opposed to the OAuth ID method, which sets up the ability for your code to run as an existing google user (that user must authorize it first).
- Clone this repo onto your laptop, create a python3 venv with
jinja2
andgspread
, and run the code. Below are steps to do this on a linux or mac from the CLI:
bash-3.2$ git clone git@github.com:amylieb/gspread-example.git
[ ... output omitted ... ]
bash-3.2$ cd gspread-example/
bash-3.2$ python3 -m venv venv
bash-3.2$ source venv/bin/activate
(venv) bash-3.2$ pip install gspread jinja2
[ ... output omitted ... ]
(venv) bash-3.2$ python create_configlets.py