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...
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...
I want to create a d3 map visualization with timeseries data which pulls data from a...
I want to create a d3 map visualization with timeseries data which pulls data from a mysql table. The map will change data every second which would jump from data which contain x datetime to data which contain x+1 datetime (for example January 1 data to January 2). How can I do this? I already know how to set up a Flask API using Python which connects my visual to the database. I just need the SQL Query to change...
You have restaurants in two major cities. You want to test out a new menu item....
You have restaurants in two major cities. You want to test out a new menu item. You offer a small sample to a random sample of customers in each city. You are interested in estimating the overall difference in proportion of customers between the two cities who would purchase this new item. In the first city, 64 out of 148 said that they would purchase the item if it was available. In the second city, 80 out of 302 said...
NOTE PLEASE I WANT ALL THE SUBPARTS** An analyst has gathered the following information about a...
NOTE PLEASE I WANT ALL THE SUBPARTS** An analyst has gathered the following information about a project: • Cost: $10,000 • Annual cash inflow: $4,000 • Life: 4 years • Cost of capital: 12% 22. Which of the following statements about the project is least accurate? * A. The discounted payback period is 3.5 years. B. The IRR of the project is 21.9%; accept the project. C. The NPV of the project is +$2,149; accept the project. D. None of...
i want an essay which represent all these content in it .essay on shawn achor ted...
i want an essay which represent all these content in it .essay on shawn achor ted talk
Which of the following is a Website query?Select all that apply.True False [Miami weather],...
Which of the following is a Website query?Select all that apply.True False [Miami weather],English (US) True False [Miami wikipedia.org],English (US) True False [Miami map],English (US) True False[Miami images], English (US)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT