Question

In: Computer Science

i want to create a weather api. which is pullling out information of all the cities(for...

i want to create a weather api. which is pullling out information of all the cities(for the whole world)  using their names or by their zipcode. and it should change the background image as the temperature is, cold, or hot, or mild etc. i need in help in making this weather api and also it can be in any language. please help me out

Solutions

Expert Solution

You can achieve Your goal using nodejs. With the help of nodejs we can send HTTP request to whether stack API or website which will give us wether information of city. First you need to sign in to wetherstack and mapbox website and generate your own access token.After getting access token just paste your access token to my code and run it.

Run command node app.js City_name it will give wether information of City name you have mentioned in your command

I have done this code in 3 files.please refer this files

gecode file converts name of city to cor-ordinates on map so that we can access the exact location of city with the help of mapbox api

forcast files send request to the wetherStack API to get information of wether

//app.js

const request = require('request');

//geocode and forcast files are store in utils folder

const geo = require('./utils/geocode')

const winfo = require('./utils/forcast')

//getting name of city

const address=process.argv[2]

console.log("address : "+address)

//calling geocode function to convert location name to cor-ordinates like longitude and lattitude

geo(address, (error,{longitude,lattitude,location})=>{

if(error)

{

console.log("Error "+error)

}

else

{

//calling winfo function which is forcast file to get wether information and its parameters are longitude and lattitude

winfo(longitude,lattitude , (error,response1)=>{

if(error)

{

console.log(error)

}

else

{

console.log("In the "+location+" wether is "+response1)

}

})



}

})

//forcast.js

const request = require('request');

const winfo= (co1,co2 , callback)=>{

//link on which we are sending HTTP request , please sign in to wether stack API and put ur access token in link to

//get code working

const url='http://api.weatherstack.com/current?access_key='Put_Your_AccessTocken_Here'&query='+co1+','+co2

request( {url: url , json: true}, function (error, response) {

if(error)

{

callback(error)

}

else

{

//creating output for user

const str1=" "+response.body.current.weather_descriptions+" it is "+response.body.current.temperature+" currently"

const str2=" but it feels like "+response.body.current.feelslike+" degree"

callback(undefined,str1+str2);

}

});

}

module.exports=winfo

//geocode.js

const request = require('request');

const geo= function(address , callback){

//please sign in to mapbox to generate your tocken and put the tocken here

const url1='https://api.mapbox.com/geocoding/v5/mapbox.places/'+address+'.json?access_token=' Put_Your_AccessTocken_Here'


//sending HTTP request

request({url:url1 , json: true}, (error , response)=>{

if(error)

{

callback(error)

}

else if(response.body.features.length === 0)

{

callback("Unable to find location try another search")

}

else

{

callback(undefined,{

lattitude:response.body.features[0].center[0],

longitude:response.body.features[0].center[1],

location:response.body.features[0].place_name

})

}

})

}

module.exports=geo

install node JS and NPM module before using this code


Related Solutions

Create a Weather API.(ANY LANUGUAGE). " that pulls out information from web and stores the data...
Create a Weather API.(ANY LANUGUAGE). " that pulls out information from web and stores the data in back end. in which users can enter location: city or zip code to get the weather of that city or state. weather info should be in degree farenhit and centigrade. it should show the images as you see in you phone for weather and speed, etc. and it should change picture according to weather. for example, rain, cloudy, sunny, night, thunder. SHOW THE...
I want to know how to get the "temp" information from a API response like this...
I want to know how to get the "temp" information from a API response like this in javascript: { "coord": { "lon": -122.08, "lat": 37.39 }, "weather": [ { "id": 800, "main": "Clear", "description": "clear sky", "icon": "01d" } ], "base": "stations", "main": { "temp": 282.55, "feels_like": 281.86, "temp_min": 280.37, "temp_max": 284.26, "pressure": 1023, "humidity": 100 }, "visibility": 16093, "wind": { "speed": 1.5, "deg": 350 }, "clouds": { "all": 1 }, "dt": 1560350645, "sys": { "type": 1, "id": 5122, "message":...
I want to find out which SPSS test I would use in this scenario: In this...
I want to find out which SPSS test I would use in this scenario: In this scenario a social psychologist working for an advertising firm was interested in whether the frequency of exposure to an advertisement would have an effect on the liking of that ad. He suggested that the more often a subject was exposed to an ad would have an effect on how much she / he would enjoy the ad. The study involved exposing a subject to...
Android Studio (Java) I'm trying to create a simple calculator. I want to put out a...
Android Studio (Java) I'm trying to create a simple calculator. I want to put out a message if they try to divide by 0. I have this so far. What code should I put? divide.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (number1.getText().length() != 0 && number2.getText().length() != 0) { double n1= Double.parseDouble(number1.getText().toString()); double n2= Double.parseDouble(number2.getText().toString()); double res= n1 / n2; result.setText(String.valueOf(res)); } else { Toast.makeText(view.getContext(), "Please enter the numbers properly", Toast.LENGTH_SHORT).show(); } } });
I WANT TO IMPLEMENT THIS IN JAVA PLEASE I want to create a small user input...
I WANT TO IMPLEMENT THIS IN JAVA PLEASE I want to create a small user input system for a university student, where they put the season and year of when they started their uni course. For example the system will ask "What year did you start your degree?", the user will input "Autumn/2022" as a string. Now from a string format as shown, it should take that user input and calculate for example +2 or +3 years to the date....
To store the information about a city and its weather forecast, create a struct that holds...
To store the information about a city and its weather forecast, create a struct that holds the city's name (string), population (int), and a forecast array storing 7 string elements representing the city's weather in the next 7 days. The program will then accept user input to enter the name and population of the city, then it accepts 7 string inputs to store into the forecast array. Then the program will output the city's name, population, and forecast data. Ex:...
Hello! I have worked out all these questions, but want to double check them with your...
Hello! I have worked out all these questions, but want to double check them with your answers before submitting them. Thanks! 1. On December 31, 20X1, a company adopted the dollar-value LIFO inventory method. Inventory at the end of 20X1 for its only inventory pool was $400,000 under the dollar-value LIFO method. At the end of 20X2, inventory at year-end cost is $473,000 and the cost index is 1.10. At the end of 20X3, inventory at year-end cost is $492,000...
I want to create an app which a user can talk to and get emotional feedback...
I want to create an app which a user can talk to and get emotional feedback in a form of a conversation. So, a user can talk about how stressful their day was, and my app should reply accordingly so that the user feels better. I want to know what methods(pyschologically) I can apply on my bot so that the user feels satisfied. In short, is there any psychological therapy term which deals with such conversations? Also, what all illnesses...
C++ programming To store the information about a city and its weather forecast, create a struct...
C++ programming To store the information about a city and its weather forecast, create a struct that holds the city's name (string), population (int), and a forecast array storing 7 string elements representing the city's weather in the next 7 days. The program will then accept user input to enter the name and population of the city, then it accepts 7 string inputs to store into the forecast array. Then the program will output the city's name, population, and forecast...
I want to create a seating chart that I can assign an 'X' to if a...
I want to create a seating chart that I can assign an 'X' to if a seat is purchased. I want to use a numpy array, but am having trouble figuring out how to write it the way I want it. I want it 4 X 15, but with string values instead of all the same value or a range. i would like this. can I do it with numpy? also I want the columns lined up when i do...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT