tasker for android - not able to get response from HTTP get request - tasker

I am trying to get some data out of google maps API.
The response comes trough, as I can see it, but when I try to use a javascriptlet, i have no luck.
this is my current setup:
I get the data from google maps:
Server:port: http://maps.google.com/maps/api/geocode/json?latlng=%LOCN&sensor=false
I run the javascriptlet trying to get only the value I need out from the json object:
var response = global ('HTTPD');
var gmapslocationname = response.results[0].address_components[2].short_name
and then I try to flash it:
%gmapslocationname
but what I get in the flash is %gmapslocationname
What am I doing wrong here?
thanks

Tasker is not capable of handling objects, hence the HTTPD is stored as a string.
To be able to use it, you need to convert it to object.
Change your code to
var response = global ('HTTPD');
var gmobject = JSON.parse(response);
var gmapslocationname = gmobject.results[0].address_components[2].short_name

Related

Append to an Azure Blob using SAS URL

I need to continuously append to a blob in a container for which I have been provided SAS URL
I am doing this
var blobClient = new AppendBlobClient(mySASUri);
var blobContentInfo = blobClient.CreateIfNotExists();
but Create or CreateIfNotExists do not take a blob name parameter. which is strange for a create method.
and I get Authentication exception when using the following
mySASUri="https://[myaccount].blob.core.windows.net/[my container]?sp=racwl&st=2022-02-03T08:29:46Z&se=2022-02-03T16:29:46Z&spr=https&sv=2020-08-04&sr=c&sig=[the signature]"
I have been reading a lot of stuff on use of Azure SAS but everything talks about generating SAS or stops at very basic level.
Thanks to anyone who looks at this and can provide either a reading reference or guidance on what api combinations should work for this use case.
Thanks,
Tauqir
Considering your SAS URL is for the container, it would be be better if you create an instance of BlobContainerClient first and then get an instance of AppendBlobClient using GetAppendBlobClientCore method.
Something like:
var blobContainerClient = new BlobContainerClient(new Uri(mySASUri));
var appendBlobClient = blobContainerClient.GetAppendBlobClientCore("append-blob-name");
...do the append blob operations here...

Google sheets IMPORTXML fails for ASX data

I am trying to extract the "Forward Dividend & Yield" value from https://finance.yahoo.com/ for multiple companies in different markets, into Google Sheets.
This is successful:
=IMPORTXML("https://finance.yahoo.com/quote/WBS", "//*[#id='quote-summary']/div[2]/table/tbody/tr[6]/td[2]")
But this fails with #N/A:
=IMPORTXML("https://finance.yahoo.com/quote/CBA.AX", "//*[#id='quote-summary']/div[2]/table/tbody/tr[6]/td[2]")
I cannot work out what needs to be different for ASX ticker codes, why does CBA.AX cause a problem?
Huge thanks for any help
When I tested the formula of =IMPORTXML("https://finance.yahoo.com/quote/CBA.AX", "//*"), an error of Error Resource at url not found. occurred. I thought that this might be the reason of your issue.
But, fortunately, when I try to retrieve the HTML from the same URL using Google Apps Script, the HTML could be retrieved. So, in this answer, I would like to propose to retrieve the value using the custom function created by Google Apps Script. The sample script is as follows.
Sample script:
Please copy and paste the following script to the script editor of Google Spreadsheet and save it. And, please put a formula of =SAMPLE("https://finance.yahoo.com/quote/CBA.AX") to a cell. By this, the value is retrieved.
function SAMPLE(url) {
const res = UrlFetchApp.fetch(url).getContentText().match(/DIVIDEND_AND_YIELD-value.+?>(.+?)</);
return res && res.length > 1 ? res[1] : "No value";
}
Result:
When above script is used, the following result is obtained.
Note:
When this script is used, you can also use =SAMPLE("https://finance.yahoo.com/quote/WBS").
In this case, when the HTML structure of the URL is changed, this script might not be able to be used. I think that this situation is the same with IMPORTXML and the xpath. So please be careful this.
References:
Custom Functions in Google Sheets
Class UrlFetchApp
An other solution is to decode the json contained in the source of the web page. Of course you can't use importxml since the web page is built on your side by javascript and not on server's side. You can access data by this way and get a lot of informations
var source = UrlFetchApp.fetch(url).getContentText()
var jsonString = source.match(/(?<=root.App.main = ).*(?=}}}})/g) + '}}}}'
i.e. for what you are looking for you can use
function trailingAnnualDividendRate(){
var url='https://finance.yahoo.com/quote/CBA.AX'
var source = UrlFetchApp.fetch(url).getContentText()
var jsonString = source.match(/(?<=root.App.main = ).*(?=}}}})/g) + '}}}}'
var data = JSON.parse(jsonString)
var dividendRate = data.context.dispatcher.stores.QuoteSummaryStore.summaryDetail.trailingAnnualDividendRate.raw
Logger.log(dividendRate)
}

How to get Parse Server DateTime?

Is there a method in Parse that would let me get the current time that is running on the server? I need to fetch the time from the server, and not depend on the local device's clock.
I'm using C#, Unity SDK. TIA!
You can create a cloud function, written in javascript, which will get the date and return it.
Parse.Cloud.define("getServerTime", function(request, response) {
var dateToday = new Date();
response.success(dateToday.toDateString());
});
You will likely want to do some specific formatting of the response so you can sensibly parse it on the client.

Windows Phone webclient caching "issue"?

I am trying to call the same link, but with different values, the issue is that the url is correct containing the new values but when I download it (Webclient.DownloadStringTaskAsync), it gives me the previous calls result.
I have tried adding headers no-cache, and attaching a random value to the call, and ifmodifiedSince header. however it is still not working.
any help will be much appreciated cause I have tried everything.
uri: + "&junk=" + Guid.NewGuid());
client.Headers["Cache-Control"] = "no-cache";
client.Headers[HttpRequestHeader.IfModifiedSince] = DateTime.UtcNow.ToString();
var accessdes = await client.DownloadStringTaskAsync(uri3);
so here my uri3 contains the latest values, but when I hover over accessdes, it contains the result as if I am making a old uri3 call with previous set data.
I saw one friend that was attaching a random GUID to the Url in order to prevent the OS to cache its content. For example:
if the Url were: http://www.ms.com/getdatetime and the OS is caching it.
Our solution was adding a guid for creating "sort of" like a new url, as an example our previous Url would look like: http://www.ms.com/getdatetime?cachebuster=21EC2020-3AEA-4069-A2DD-08002B30309D
(see more about cache buster : http://www.adopsinsider.com/ad-ops-basics/what-is-a-cache-buster-and-how-does-it-work/ )

Google Spreadsheet API - returns remote 500 error

Has anyone battled 500 errors with the Google spreadsheet API for google domains?
I have copied the code in this post (2-legged OAuth): http://code.google.com/p/google-gdata/source/browse/trunk/clients/cs/samples/OAuth/Program.cs, substituted in my domain;s API id and secret and my own credentials, and it works.
So it appears my domain setup is fine (at least for the contacts/calendar apis).
However swapping the code out for a new Spreadsheet service / query instead, it reverts to type: remote server returned an internal server error (500).
var ssq = new SpreadsheetQuery();
ssq.Uri = new OAuthUri("https://spreadsheets.google.com/feeds/spreadsheets/private/full", "me", "mydomain.com");
ssq.OAuthRequestorId = "me#mydomain.com"; // can do this instead of using OAuthUri for queries
var feed = ssservice.Query(ssq); //boom 500
Console.WriteLine("ss:" + feed.Entries.Count);
I are befuddled
I had to make sure to use the "correct" class:
not
//using SpreadsheetQuery = Google.GData.Spreadsheets.SpreadsheetQuery;
but
using SpreadsheetQuery = Google.GData.Documents.SpreadsheetQuery;
stinky-malinky
Seems you need the gdocs api to query for spreadsheets, but the spreadsheet api to query inside of a spreadsheet but nowhere on the internet until now will you find this undeniably important tit-bit. Google sucks hard on that one.

Resources