LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Passing variables between bash and google docs (https://www.linuxquestions.org/questions/programming-9/passing-variables-between-bash-and-google-docs-4175700101/)

michael.glenn.williams 08-31-2021 08:02 PM

Passing variables between bash and google docs
 
I have a similar need to this that cannot be solved by using only bash. I need to update a cell on a Google sheet from bash. I also need to fetch/wget/curl a cell from a sheet into a bash variable. Is the only way to do this with the clasp command line tool from bash? If someone could provide a command within bash that sets a bash variable to the value of a cell in a sheet that would be perfect. Thank you!

ondoho 09-02-2021 11:04 AM

Quote:

Originally Posted by michael.glenn.williams (Post 6280394)
I have a similar need that cannot be solved by using only bash. I need to update a cell on a Google sheet from bash. I also need to fetch/wget/curl a cell from a sheet into a bash variable. Is the only way to do this with the clasp command line tool from bash? If someone could provide a command within bash that sets a bash variable to the value of a cell in a sheet that would be perfect. Thank you!

I think it would be best if you started your won thread with a useful problem description. Read the first 2 non-covid links in my signature for hints.

Generally speaking: Google Docs is full on javascript, command line downloaders like curl or wget won't help you get at the actual document.
Command line javascript engines exist, been a while for me, phantomjs comes to mind, or just your browser in headless mode.
So that's just for the fetching.

How to massage the doc with bash, no idea. Same answer as rtmistler's still applies I guess.

Bash does not have a command line tool named clasp. Could be some 3rd party CLI utility?

edit: searching my package manager for "google docs" gives a few results, one of them looks useful: gdatafs

astrogeek 09-02-2021 12:32 PM

Welcome to LQ and the Programming forum!

Your question is complete within itself and more suitable as its own thread and has been moved accordingly. A link to the originally referenced thread has been inserted.

chrism01 09-03-2021 12:22 AM

As mentioned by ondoho, there's a lot more to it, so bash is prob not the lang to use.

Are you averse to using Perl?
Perl has a lot(!) of interfaces into specialist tools like google spreadsheets and in fact here's a module to do what you need https://metacpan.org/pod/Net::Google::Spreadsheets

pan64 09-03-2021 01:26 AM

if I understand well this is the official documentation: https://developers.google.com/sheets...te#apps-script
and you will find some examples on the bottom of that page.

michael.glenn.williams 09-03-2021 02:44 PM

I could use the proper way to access the Google spreadsheet from bash as well.
Although @Entropy1024 suggested an alternative, the spirit of the post is to
access Google sheets from bash. There is now the Sheets API :
https://developers.google.com/sheets/api/guides/values
and the Google Apps scripts:
https://developers.google.com/sheets...rt/apps-script
but nothing directly from CLI as it seemed there was with curl or wget back in the day.

maw_walker 09-03-2021 03:01 PM

If I had to guess, authentication would be a problem from bash but I've not done this so can't speak to it exactly. Google uses oauth2 for authentication I believe. No idea if helpful but may be: https://developers.google.com/identity/protocols/oauth2

ondoho 09-04-2021 12:20 AM

Quote:

Originally Posted by michael.glenn.williams (Post 6281352)
I could use the proper way to access the Google spreadsheet from bash as well.

Please define "from bash". I can wrap any program in a short shell script and run it "from bash", but then there's no real need to use bash at all (other than maybe wrap together a few separate commands).

Quote:

the spirit of the post is to access Google sheets from bash. There is now the Sheets API :
https://developers.google.com/sheets/api/guides/values
and the Google Apps scripts:
https://developers.google.com/sheets...rt/apps-script
Looking at these links, there's nothing that suggests bash, or even any sort of Linux command line interface.
Maybe you confuse usage of the word "script", but that's not bash or Linux CLI at all. AFAICS, it's javascript but I might be wrong (extension ".gs" - probably stands for google script, lol).

Quote:

but nothing directly from CLI as it seemed there was with curl or wget back in the day.
As I wrote before, there's no way curl or wget was ever an option with Google Docs.


All times are GMT -5. The time now is 06:42 PM.