What is the easiest way to run a python script from google sheets, or alternatively execute the python script when the google sheets opens?
I'm assuming you have some python asset that you would like to use to modify data on Google Sheets. If that's the case, then I think your best option is to use Google APIs to access Google Sheets from python. You can use any of the following two tutorials by Twilio to achieve that.
If you want to add the python asset into Google sheets (Ex. as a custom function), then it will be much easier to rewrite it in JS.
Related
I am looking for a way to issue SQL queries to a Google Sheet using Python.
I know that Google Sheets has a function called query that can be used to issue SQL queries from within the spreadsheet itself,
https://support.google.com/docs/answer/3093343?hl=en
Is there some way that I can call this function using Python? Maybe through the gspread module?
I expected there to be a way to call Google Sheets functions (like COUNT, SUM and others) using this package.
I am open to trying other methods as well. Basically, I want to query a Google Sheet like a database using Python.
I'm trying to have a python script update a google sheets. The script scrapes a dynamically loaded webpage and retrieves some values.
Because the site loads dynamically, I can't use google scripts. But if I wan't the python script to access the google sheet, I need a google service account. This requires a credit card, but I don't have access to a non-prepaid one.
I could also host the python API on gae, but this also requires a credit card.
Any ideas for how I could work around this?
I believe your goal as follows.
You want to put the values to Google Spreadsheet using python.
In order to achieve your goal, how about the following patterns?
1. Access to Google Spreadsheet using Sheets API with OAuth2.
When Sheets API is used, the values can be put to the Google Spreadsheet.
In this case, you can see the sample script at Quickstart. And, I think that in your situation, the use of Google Sheets API is free of charge. If you want to increase the quota of Sheets API, please check it at https://developers.google.com/sheets/api/limits.
2. Access to Google Spreadsheet using Sheets API with Service account.
When Sheets API is used, the values can be put to the Google Spreadsheet.
In this case, you can see the sample script from these threads. And also, I think that in your situation, the use of Google Sheets API is free of charge.
3. Access to Google Spreadsheet using Web Apps created by Google Apps Script.
When Google Apps Script is used, the values can be put to the Google Spreadsheet. And, in this method, Google Apps Script is used as the wrapper.
At first, create Web Apps using Google Apps Script, and your python script accesses to the Web Apps by sending the values with requests module. By this, at the Web Apps side, the retrieved values are put to Google Spreadsheet using Google Apps Script. The Web Apps is used as the wrapper API for using Google Spreadsheet. And also, in this case, you can also access to the Web Apps with and without using the access token. In this method, I think that your python script is simple modification.
In this case, you can see the detail information about Web Apps at Web Apps and Taking advantage of Web Apps with Google Apps Script.
I have access to a bloomberg terminal and python on the same computer. I tried to look on internet and on this forum for some useful tips/introduction to automate bloomberg tasks, although I didn't find anything. How can the terminal be automated? Is it possible to do something similar to webscraping with an external application? Or the only way is to use Sendkeys method? (In my case I want to automate ISIN typing, print screen (for which I found a code in this forum using API calls) and data analysis (so scrape the data showed). I'm aware of bloomberg add-in for excel but it's quite limited.
Automating the terminal can be done using the TerminalConnect Api.
It's not possible to 'scrape' data from the terminal, but you can access data using the Desktop Api (DAPI).
What you want is to use the API.
Bloomberg makes it easy to do this in Excel. You need to install Bloomberg API plugin.
If you need to do this ‘programmatically’, there are API written in different languages. Use WAPI in your terminal to find out.
Hey all I am looking to use GAE to listen to one of my Google sheets pages and then execute a python script based of what was entered. I have already setup the python and sheets interaction, meaning I can now read everything off my sheet when I run my code. I am having trouble understanding how to setup GAE to "listen" for changes an the sheets though. I have setup the GAE using:
https://cloud.google.com/appengine/docs/standard/python3/quickstart
But not sure how to integrate this using my sheets. Any help would be great!
What you want is doable but not in the same way you described. GAE cannot listen to Google Sheets. The usually interaction is with the Google Sheets API, which will require you firing off API calls to check for a certain sheet/cell for updates.
Since you are looking for a "push" solution, you will need to do it from Google Sheets' end. You need Google Sheets to fire off a request to your GAE and then you can process the information. I would suggest you code your GAE handler to process GET requests and then have your Google Sheets fire off a script to set a request to your GAE URL. You will set the script to trigger whenever the desired update on your sheet is performed.
I dont even know if this is possible. But if it is, can someone give me the broadstrokes on how I can use a Python script to populate a Google spreadsheet?
I want to scrape data from a web site and dump it into a google spreadsheet. I can imagine what the Python looks like (scrapy, etc). But does the language support writing to Google Drive? Can I kick off the script within the spreadsheet itself or would it have to run outside of it?
Ideal scenario would be to open a google spreadsheet, click on a button, Python script executes and data is filled in said spreadsheet.
Google GData (library with interfaces for all Google services) Python client:
https://code.google.com/p/gdata-python-client/
Spreadsheets API docs (linked from previous page):
https://developers.google.com/google-apps/spreadsheets/?csw=1
The question is from 2013. But still, as I was interested today by the answer, I though it could help some other people :
Google developed GScript, equivalent of VBA from Microsoft. I guess with this language you can easily scrape web data and include them into the sheet.
Otherwise, if you want to use Python, here is a great tutorial explaning how to use Google API v4:
https://developers.google.com/sheets/api/quickstart/python
The missing step: launching python script directly from the google sheet.
I hope it helps !
Yes, it is possible and this is how I am personally doing it so.
search for "doGet" and "doPost(e)