0

all, my purpose is to download a spreadsheet file as local csv file. And after some test, I now come to the solution use the doGet() as below:

function doGet(){
...
var output = ContentService.createTextOutput().setContent(csvOriFile).downloadAsFile(fileName);
return output;
}

The csv file can be downloaded using the url as below in the browser: https://script.google.com/macros/s/AKfycby45YEyOpgBruiq1DBa4A2eBAXau8EH.../exec"

As I want to set it as a weekly auto-fetched process, I want to write a bash script to run the url to get the csv file. But I do not know how to do this. As this also related to gmail authentication. I searched some solutions, seems this link is what I want, but that question also got no answers. I tried to run and modify that script, use curl to do authentication first, and then use curl to fetch the file, but failed. Can anyone help? Thanks

Solution: I later used google drive API to do the work.

Community
  • 1
  • 1
zhihong
  • 1,808
  • 2
  • 24
  • 34

1 Answers1

0

No Problem. What we want is a loop that has a sleep in it. Here I am going to use wget, if you don't have either get it or use curl.

#!/usr/bin/env bash

while true; do
    wget https://script.google.com/macros/s/AKfycby45YEyOpgBruiq1DBa4A2eBAXau8EH.../exec
    sleep 604800
done

If you need to convert the xlsx to csv every week, then this is what you could do. add it before the sleep in the loop. Convert xlsx to csv in linux command line

You may also need to consider using wget with an alternate file name or a subdirectory for each week. We do't want to replace that. We can define the date in bash as d=date +%m%d_%H%M

Community
  • 1
  • 1
PhysicalChemist
  • 540
  • 4
  • 14
  • hi, thanks for your suggestion. As this also related to google authentication, sorry that did not mention it clearly in my question. So, it dose not work if directly wget that link without browser. – zhihong Aug 22 '14 at 11:00
  • wget has the ability to authenticate. The first two answers are found here are will do it. http://stackoverflow.com/questions/4272770/wget-with-authentication – PhysicalChemist Aug 28 '14 at 15:36