This was written for Brown University's Online Course Reserves Application, but should be generic enough for any MySQL-backed application (and should be easy enough to make more generic for other databases).
-
Create a Google service account key and save the credentials in JSON format.
-
Create a new folder in Google Drive and save it with the service account you just created.
-
Create a table like this in your database (you can replace the name
reportswith anything):CREATE TABLE `reports` ( `run_order` INT(11) NOT NULL, `name` VARCHAR(100) NOT NULL, `query` MEDIUMTEXT NOT NULL, `description` VARCHAR(500) NOT NULL DEFAULT '', PRIMARY KEY (`name`), UNIQUE INDEX `order` (`run_order`) ); -
Copy the file
ocra-data.conf.example.yamltoocra-data.conf.yamland update with your database credentials, the name of your "reports" table, the ID of the new folder you created (you can copy this from the folder's URL), and the path to the service account credentials .json file. -
Add your reports to your
reportstable.runorderdetermines the order of reports in the output spreadsheet;namedetermines the name of the sheet and will appear, along withdescriptionon the first page of the file as a table of contents. Thequeryis simply an SQL statement that returns the data you want to save to the spreadsheet. -
pip install -r requirements.txt -
Set an environment variable,
GOOGLE_APPLICATION_CREDENTIALS, to the path to your service account credentials file (the.jsonfile from step 1). -
python ocra-reporting.py.