Google sheets handling async loads - arrays

I have a google drive sheet that I am trying to load data. In selenium, I can go to the page and wait for a second then parse the page. Is there anyway to wait in a similar manner?
I am trying to get the data from this table :"https://www.cboe.com/delayed_quotes/vix/future_quotes/"
=IMPORTHTML("https://www.cboe.com/delayed_quotes/vix/future_quotes/","table",1)
returns
N/A
Imported content is empty.

importing JavaScript elements is not supported in google sheets:

I believe your goal is as follows.
You want to retrieve the table in the site of the URL https://www.cboe.com/delayed_quotes/vix/future_quotes/.
Issue and workaround:
When I saw the HTML data of the URL, it seems that your expected table is not included. But, I notice that the table is created by Javascript using the values retrieved from the API. So, in this answer, I would like to propose directly retrieving your expected values from the API. In this case, the retrieved value is JSON data. So, I would like to propose using a Google Apps Script as a custom function.
Sample script:
Please copy and paste the following script to the script editor of Spreadsheet, and save the script. When you use this script, please put a custom function of =SAMPLE() to a cell. By this, the values are returned.
function SAMPLE() {
const url = "https://www.cboe.com/us/futures/api/get_quotes_combined/?symbol=AMT1&rootsymbol=null";
const res = UrlFetchApp.fetch(url);
const obj = JSON.parse(res.getContentText());
const header = ["symbol", "expiration", "last_price", "change", "high", "low", "settlement", "volume"];
return obj.data.map(o => header.map(h => o[h]));
}
Testing:
When this script is tested, the following result is obtained.
Note:
This answer is the current answer. When the specification of the site and the API is changed, this script might not be able to be used. So, please be careful about this.
References:
Custom Functions in Google Sheets
fetch(url)

Related

Converting CSV to JSON to send POST From React to Flask API

I am attempting to send a POST request to my API from my React app and am figuring out how to change a CSV from input to JSON format so no downloading needs to take place. I have seen people use Papaparse but from what I saw was that it hadn't been updated in a while so I am looking for other options.
const handleSubmit = async (event) => {
event.preventDefault();// from elements property
console.log(event.target.returns.value)
console.log(await axios.post('http://127.0.0.1:5000/ratios', event.target.returns.value))
setShow(true)
};
If I just send like this I get a 500 error and the first line of my POST function on Flask is
df = request.get_json()
maybe there's an easier way but let me know if you have any insight or advice. Thank you in advance
Your question is somewhat confusing and I think it's due to your understanding of how csv and json would interact. CSV is essentially a way to send tables of data, it doesn't have an inherent key pair structure so you need to do a little work to convert it. I'm not familiar with flask specifically but it looks like df = request.get_json() is trying to parse what it expects to be json but is instead csv. You are right that you need to convert that. Papaparse seems like an excellent option and is still under active development. However I don't think that really matters since csv and json are formats that haven't changed in a long time so the task of converting them hasn't changed. So whether or not there has been recent development doesn't matter.
If you decided to roll your own you could probably get close by taking each row and turning that into an object then matching each row entry with a first row key label or just with saved constants. Depend on how your csvs are structured.

How do get the result from REST website that returns only text?

I'm trying to use a REST web service from Geonames.org. When I try to manually put in the url with the parameters, it would only return the Country Code. I've tried to search for ways to implement it, but most of what I've seen return JSON text with multiple keys and data. I feel like the answer should be pretty simple, but I'm unsure.
I'm trying to use this for a React project I'm working on.
Here is an example of what the url returns
Just looked into the docs of that API, and it says if you want to receive JSON responses simply add JSON keyword to the endpoint. Like here for given endpoint you have:
http://api.geonames.org/countryCodeJSON?formatted=true&lat=47.03&lng=10.2&username=demo
so just change countryCode to countryCodeJSON.
Source: http://www.geonames.org/export/JSON-webservices.html

Obtaining Weather Data From NOAA

I am trying to use the API to return data from the Chagrin Falls station in Ohio. I can get the data from the website so I know there is data, but the API does not return any values.
I have a valid token and the examples in the documentation work, but if I try any to alter the examples in any way I get nothing back just any empty json object {}.
Example I am trying to use:
https://www.ncdc.noaa.gov/cdo-web/api/v2/data?datasetid=GSOM&stationid=GHCND:US1OHGG0014&units=standard&startdate=2020-08-01&enddate=2020-08-01&limit=1000
Data from the website:
https://www.ncdc.noaa.gov/cdo-web/datasets/GHCND/stations/GHCND:US1OHGG0014/detail
I don't exactly know how you are going to achieve this since you haven't told us what programming language you are using. However, with python I use a module called urllib to extract raw html data from a url that can be seen from the browser using ctrl+u.

Adding Editors to a Google Document with Google Apps Script

I'm trying to add editors and viewers to a Google Doc using Google Apps Script. The documentation of addEditors() says that:
Adds the given array of users to the list of editors for the Document.
I can't figure out how to configure or use an array for this. The array is determined by values passed from a different script file.
Well, without any code to start with you need to do something like the following:
function addEditors() {
var emails = [
'john#example.com',
'steve#example.com',
'bill#example.com'
];
DocumentApp.getActiveDocument().addEditors(emails);
}
Arrays are a variable type in Javascript that you need to know to get started with Apps Script.
You can read more about arrays here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array
Or get some practice at FreeCodeCamp: https://www.freecodecamp.com/challenges/store-multiple-values-in-one-variable-using-javascript-arrays
Good luck.

Getting $http.put() to send correctly formatted data, instead of JSON object

So, I spent some time and built a quick API for a project that I'm doing for myself.
I used the Postman add-on for Chrome to mimic PUT and DELETE quests to make sure everything worked correctly. Really happy I did that, as I learned a lot about PHP's shortcomings with PUT and DELETE requests.
Using the API I've had working with Postman, I started moving everything over to AngularJs controllers and such.
I'm trying to get a user to claim a row in a database as the login information for the users is different than this particular information. I couldn't figure out why the put requests to claim the row in my database wasn't working. Lo and behold, the data being parsed from my parsestr(file_get_contents('php://input')) had 1 array key, which was a JSON string.
I've looked, and I can't seem to find a solid answer either through Stackoverflow or Google (maybe I missed it somewhere in the config options), So my question is this: is there any way I can get the $http.put call send the data to the server correctly?
Thanks to user Chandermani for pointing me to the link at this URL which answered the base of my question.
From the above link, I found myself on This Blog post submitted by another user. In the end, what I ended up doing was the following:
taking param() function from the above link, as well as implementing these lines of code:
var app = angular.module('ucpData', [] , function($httpProvider){
$httpProvider.defaults.transformRequest = [function(data) {
return angular.isObject(data) && String(data) !== '[object File]' ? param(data) : data;
}];
});
Is how I worked around the problem. For some developers, you may actually want to keep the default transformRequest settings, but for the project I am doing I know that I will end up forgetting to call param() at some point, and my server doesn't naturally accept json data anyway. I would caution future developers to consider what they are attempting to do before they alter the transformRequest array directly.

Resources