nonprofitgibi nonprofitgibi - 1 year ago 63
Python Question

Useing python to download a file in google drive that is created by a google app script

Ok so I've got a google script that I'm working on to help out with some stuff and I need to be able to create a txt file and download it to my local computer. I've figured out how to create the file as a blob and create a file in google drive.

The problem is that I for one can't figure out how to delete the old file and create the new file and I also can't seem to figure out how to download it locally so I can work my python magic and create a nice looking report and print it out. I've gone over the documentation and looked at similar questions but I can't figure out how to actually download a file.

An example program would be great answer for me something that uses a dummy file and downloads it, really that would be awesome.

My thoughts are that I could go back to the old file that I am trying to download and just edit it so that way I don't have to actually delete the file which would make it have the same ID's, meta data, and URL.

Can I use the google app script to download it directly to my computer and for a little added info I run a Linux machine so some things are a little more labor intensive for me while some other stuff is nice and easy. I feel like there is an app that can run on my computer locally that stores my google drive files locally and I could possibly just grab it from there.

Lastly a link to documentation for running the scripts natively would be helpful as well.


This is how to download a file in google drive using Python.

# sample
import googleDriveAccess
ci = googleDriveAccess.readClientId(basedir)
ds = googleDriveAccess.second_authorize(basedir, ci, script=True)
id, fileobj = googleDriveAccess.script_download(ds, folder, SCRIPT_ID)

source code of googleDriveAccess:

Apps Script Crash Course: Import/Export Apps Script Code

Google Drive SDK: Searching for files