Skip to content

Instantly share code, notes, and snippets.

@gornostay25
Last active June 9, 2022 18:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gornostay25/c50afd6608e491e61620eb3fb589d9b8 to your computer and use it in GitHub Desktop.
Save gornostay25/c50afd6608e491e61620eb3fb589d9b8 to your computer and use it in GitHub Desktop.
Export your google app script project to a local directory. Python
import requests,configparser
filename = "GASsettings.ini"
config = configparser.ConfigParser()
config.read(filename)
if not "GAS" in config:
print("Please create "+filename+" file!")
exit(1)
exportFolder = "./MyGASproject"
scriptid = config["GAS"]["script_id"]
authGoogleToken = config["GAS"]["token"]
filelist = [ f for f in os.listdir(exportFolder)]
for f in filelist:
os.remove(os.path.join(exportFolder, f))
r = requests.get("https://script.google.com/feeds/download/export?id="+scriptid+"&format=json",headers={
"Authorization": "Bearer "+authGoogleToken
})
files = r.json()["files"]
print("-"*30)
print("Exporting "+str(len(files))+" file(s)")
for x in files:
ftype = x["type"]
if ftype == "server_js":
ftype = "gs"
with open(exportFolder+"/"+x["name"]+"."+ftype,"w") as f:
f.write(x["source"])
print("-"*30)
[GAS]
script_id = blabla
token = blabla
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment