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.
Related
I am trying to use Google Sheets API to load data into EC2 using Python.
So, I tried this quickstart.
But I am stuck configuring OAuth client to get credential.json file. I can't understand what drop-down type I should select.
Hope I was clear. Thanks in advance for your time.
Depending on the type of applications you want to create, you will have to choose one of the options provided in the dropdown.
Since you want to use a Python script, you can use the credentials of type Desktop and connect to AWS EC2 from the same application. However, you can always create new ones in the corresponding GCP project to match the application you are working on.
Reference
Sheets API Authorize Requests.
I am trying to read google sheet from google app engine using gspread-pandas package. In local machine, we usually store google_secret.json in specific path. But when it comes to app engine, I saved the file in /root/.config/gspread-pandas/google_secret.json but even then I am getting the same error as below
Please download json from https://console.developers.google.com/apis/credentials and save as /root/.config/gspread_pandas/google_secret.json
2) To add to this, I have created credentials part from the GCS and now trying to get the dict file in Spread class of gspread pandas. But, since we need to store the authorization code the first time, the app engine access, the failure is still happening for google app engine
Thank you in advance
In order to achieve your technical purpose - doing operations with Google Sheets from App Engine, I would recommend you to use the Google Sheets API 1. This API let's you read and write data, format text and numbers, create charts and many other features.
Here 2 there is a quickstart for Python, for this API. If you stil encounter compatibility issues, or you have a hard time getting/ storing the credentials in a persistent way, you can always opt for App Engine Flexible, which offers you more freedom 3.
So I have used Service account key and read the service account key from GCS. This process solved my problem
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.
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.
I'd like to allow my Google App Engine application to connect to a clients Google Spreadsheet on their Google Drive. I've spent the last two and a half days trying, and I've gotten nowhere. Half of the GAE Python documentation seems to be out of date. For example some of the examples have webapp, and they don't work until I change them to webapp2, but that doesn't always work.
I created a OAuth2.0 thing (not really sure what to call it) at:
https://code.google.com/apis/console/
So now I have a Client ID and Client Secret, but one doc talked about a CONSUMER_KEY and CONSUMER_SECRET. So are they the same or?
I followed the following doc to use OAuth to read my tasks (I know it's a different API), but I couldn't figure out step/Task 3. I'm not sure if I have all of the files/librarys to connect using OAuth. I have the gdata-2.0.17 files, and I know how to connect to the drive and spreadsheets by hard coding the login credentials, but no user is going to give me their credentials.
I don't normally ask for code, or even help, but I'm completely lost with this whole OAuth API/Service.
If someone could post some sample code that uses OAuth 2.0 and webapp2, and that you have tested, that would be awesome.
If someone could link me to a sample GAE Python project that can authenticate with Google's servers and allow it to connect to the users spreadsheets using OAuth 2.0 and webapp2, I'd be over the moon.
A complete example application using Google Drive from GAE is explained in this article.
See Retrieving Authenticated Google Data Feeds with Google App Engine (Python) if you need to access the spreadsheet content.
The samples in this article is using Google Document List API but it could be easily adapted to use spreadsheets scope and spreadsheet client or service.
If you only need to list the files, I would recommend using Drive like #SebastionKreft suggested