Exception: Invalid Argument - API Weather Current Data Pull - api

I'm and Old man trying to learn a new trick. 1st post. be merciful please. I keep getting this Message. Ive tried console logging it (line 13) get the same message.
All i want is to pull High low data from the openweather site for a designated city named in A2 of my spreadsheet.
The log isnt showing my API key or the location from the A2 location. ive looked at this for 2 hours and my eyes are crossing. Like i said im new. Im sure its something i have done wrong. Thanks in advance.
Message Exception: Invalid argument: http://api.openweathermap.org/data/2.5/weather?q={location}&appid=${key} (line 14, file "Code")
function getCurrentData() {
//API key
const key = "API key Here(actually a number)"
const ss = SpreadsheetApp.getActiveSpreadsheet()
const wsLocation = ss.getSheetByName("Location")
const wsLiveData = ss.getSheetByName("Live Data")
const location = wsLocation.getRange("A2").getValue()
const highCell = wsLiveData.getRange("B4")
const lowCell = wsLiveData.getRange("C4")
let apiURL = 'https://api.openweathermap.org/data/2.5/weather?q=${location}&appid=${key}'
//console.log(apiURL)
const resText = UrlFetchApp.fetch(apiURL).getContentText()
console.log(resText)
}

The issue appears due to fetching an invalid url.
Noting in the url that syntax ${} appears, you were attempting to define the url using template literals in a normal string.
To define a template literal string you should use the backtick character ( ` ) instead of quote character ( ' ).
More information about template literals can be found here:
Template literals (Template strings)

Related

Cannot read property 'getDataRange' of null [duplicate]

This question already has an answer here:
How to fix 'TypeError: Cannot call method "getRange" of null' in Google Apps Script
(1 answer)
Closed last year.
Im very new working with google script and APIs and Im trying to run a piece of code that makes the sheet in to a Json however I`m facing an issue where it says:
TypeError: Cannot read property 'getDataRange' of null
json # Code.gs:4
The code I`m using is the following:
function json() {
const spreadsheet = SpreadsheetApp.getActiveSpreadsheet()
const sheet = spreadsheet.getSheetByName("APItest")
const data = sheet.getDataRange().getValues()
const jsonData = convertToJson(data)
return ContentService
.createTextOutput(JSON.stringify(jsonData))
.setMimeType(ContentService.MimeType.JSON)
}
I already tried to change the getSheetID but also didn`t work
Probably you're getting null value after the execution of
const sheet = spreadsheet.getSheetByName("APItest")
And That's why you get the error in the next statement. make sure that the sheet is not null.

React Native) Concatenate variable (or JSX element) inside string

I am trying to concatenate a variable that I pull with a Redux selector into a string, which ultimately reads a URL.
I seem to be getting the syntax wrong, as I keep getting results for just the string "ticker" or nothing at all.
Could someone advise me on this?
I have tried the following but to no avail:
'string ${variable} string';
{'string' + variable + 'string'}
'string' + {variable} + 'string'
My code:
const { selectedTicker } = useSelector(navigationSelector.all);
const selectUrl = 'https://openapi.naver.com/v1/search/news.json?query=${selectedTicker}&display=5&start=1&sort=sim';
Thanks in advance!
Use Template Literals.
That key above your "Tab" Key. Use That. And then wrap around your string with it.
Here.
const selectUrl = `https://openapi.naver.com/v1/search/news.json?query=${selectedTicker}&display=5&start=1&sort=sim`;

Elasticsearch not accepting size

So I have a search created with elasticsearch request within Vuejs that runs great and all works but as soon as I add any size/from parameters into the query I get the error "Options contains invalid key: size" but I'm unsure of where it's going wrong. I have tried changing it to a get and I have tried rebuilding the query in several different ways but keep getting the same result.
let buildURL = 'https://blahblahblah.com/search';
const article = { query: query.query,
size: 50
};
const headers = {
'Authorization':'$token',
'Content-Type':'application/json',
};
let querydata = await $axios.$post(buildURL, article, { headers });
Options contains invalid key is not an error coming out of Elasticsearch directly. The component you're interacting with is called App Search and is a search engine layer on top of Elasticsearch.
So, all you need to change is the following:
const article = { query: query.query,
page: { size: 50 } <---- change this line
};
That should do the trick
passing of param size index option not define
Or there might be another option to get size , might be limit 0,50
Share interface file

Firestore document with umlaut, two different "ö"

My problem is, when I try to set up a new document in my firestore with a name including umlaut "ö" it writes it in a worse way. Can you compare both documents and tell me what the difference between these two "ö" are? In the first picture the "ö" is bigger than in the second picture. Because of that my further functions - for example search function which is looking for the document name - is not working for document names with umlaut. I can't figure out the answer of my problem. I hope you guys can show me the right way to handle this. I don't want to replace the umlauts.
Should I decode my variable which I pass as the document name in my setup function?
First image:
Second image:
Update:
I will explain a little bit more about my goal. I have an index.html upload form for multi-image upload to Firebase storage and writing the imageurl and other information to the |irestore. When I upload my image folder, I retrieve the path of the imagedata from my system and make a split to have only the foldername. I use this name as the document name for my firestore (it is working for folders without an umlaut in the name). But when I write the same name for creating a document through the firebase console or replace it with a variable text = "my string for foldername" it is not matching. I would say the retrieved foldername has a different coding for example for the letter "ö".
var relpath = files[i].webkitRelativePath;
folder = relpath.split("/");
var foldername= "";
//foldername = unescape(encodeURIComponent(folder[0]));
foldername = folder[0];
var storage = firebase.storage().ref().child('kitaDE/duesseldorf/'+foldername+'/'+files[i].name);
//upload file
var upload = storage.put(files[i]); //webkitRelatviPath hinzugefügt
//update progress bar
upload.on(
"state_changed",
function progress(snapshot) {
var percentage =
(snapshot.bytesTransferred / snapshot.totalBytes) * 100;
document.getElementById("progress").value = percentage;
},
function error() {
alert("error uploading file");
},
function complete() {
document.getElementById(
"uploading"
).innerHTML += `${files[i].name} uploaded <br />`;
},
);
db.collection("kitaDE").doc(foldername).set({
image: [],
id: "",
active: true,
title: "",
street: "",
zipcode: "",
location: "",
})
Update 2
I copy & paste the foldername and my direct entry for the name over the firebase console.
Foldername copied:
Am Köhnen
Entered name in firbase console through my keyboard:
Am Köhnen
It looks for me the same. I run my javascript code and give out the following part on the console log.
var relpath = files[i].webkitRelativePath;
folder = relpath.split("/");
var foldername= "";
foldername = folder[0];
var foldername2 = "Am Köhnen";
var foldername3 = decodeURIComponent(escape(foldername2))
My result is the following screenshot.
Console.log Output
You can see that first name seems right, but first and the third output names are not matching. It seems like they are the same but they not, i refer here to my both picture at the begin of my post here. Firestore handle the names different.
To get a hex dump, I ran this command in the parent directory of the problematic one:
bash$ printf '%s\n' Am\K*hnen | xxd
00000000: 416d 204b 6fcc 8868 6e65 6e0a Am Ko..hnen.
There are multiple sequences that result in an ö character being displayed. One of them uses a single Unicode codepoint to represent the character (U+00F6), but the other actually uses a separate codepoint for the o and then another one for the umlaut (U+006F U+0308).
Also see:
The wikipedia page on combining characters
The wikipedia list of unicode characters
My first idea is that the two titles in your documents are written with different Unicode sequences.
I thought that Firestore would equate these two ways of writing, but I can't find anything in the documentation about that now. If it doesn't, then that would explain why a query that matches one of the codepoint combinations for ö doesn't match the other combination.

Get HTML Data,HTML Tags from API in React-Native

I'm making mobile app with React-Native and i wanna get data from my API.But my API's datas , databases has html tags (you can see them in images which i shared) and some character codes because there are also Turkish characters.I already was using this API from my web site and there was no problem but when i try to get data to my react native app , it is getting data as a plain text as you see in my images.How can i get this datas without problem
It's called HTML entity. This is the code that works on browser (not on your case)
var decodeEntities = (function() {
// this prevents any overhead from creating the object each time
var element = document.createElement('div');
function decodeHTMLEntities (str) {
if(str && typeof str === 'string') {
// strip script/html tags
str = str.replace(/<script[^>]*>([\S\s]*?)<\/script>/gmi, '');
str = str.replace(/<\/?\w(?:[^"'>]|"[^"]*"|'[^']*')*>/gmi, '');
element.innerHTML = str;
str = element.textContent;
element.textContent = '';
}
return str;
}
return decodeHTMLEntities;
})();
The code are copied from here HTML Entity Decode
But it only works on the browser because the browser are automatically translate the characters for you.
I don't think passing around unserialized data like this is a good idea. You might want to encode data in server side using url encode or something then decode it in the react-native side
Reference
https://www.w3schools.com/charsets/ref_utf_punctuation.asp
Actually i solved it with this : https://github.com/archriss/react-native-render-html
Thanks