Sorry if this is incorrectly posted, I am new to all of this.
I have a weather API that provides weather conditions in the variable called conditions. I would like to take that variable and make a if statement function with it as a parameter. I will be then setting the variable weather_genre for the second API to this function ("Horror" is a place holder).
// location get api $.getJSON("https://ipgeolocation.abstractapi.com/v1/?api_key=41b35af8793c40819cf4cf013b54802c", function(data) { console.log(data); var longlat = data["longitude"]+","+ data["latitude"];
// weather get api (long,lat)
$.getJSON("https://devapi.qweather.com/v7/weather/now?unit=i&lang=en&key=86a7ff0e360e463db560e321bd071d25",{"location" : longlat}, function(data){
console.log(data);
var conditions = data["now"]["text"];
//$('#weather').html(conditions);
});
})
//anime post api
var weather_genre = "Horror";
// Here we define our query as a multi-line string
// Storing it in a separate .graphql/.gql file is also possible
var query = `
query ($genre: String) { # Define which variables will be used in the query (id)
Media (type: ANIME, genre: $genre) { # Insert our variables into the query arguments (id) (type: ANIME is hard-coded in the query)
id
title {
english
}
}
}
`;
// Define our query variables and values that will be used in the query request
var variables = {
genre: weather_genre
};
// Define the config we'll need for our Api request
var url = 'https://graphql.anilist.co',
options = {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
},
body: JSON.stringify({
query: query,
variables: variables
})
};
// Make the HTTP Api request
fetch(url, options).then(handleResponse)
.then(handleData)
.catch(handleError);
function handleResponse(response) {
return response.json().then(function (json) {
return response.ok ? json : Promise.reject(json);
});
}
function handleData(data) {
console.log(data);
}
function handleError(error) {
alert('Error, check console');
console.error(error);
}