weather forcast in python-

 '''

WEATHER FORCAST


'response.content() # Return the raw bytes of the data payload
response.text() # Return a string representation of the data payload
response.json() # This method is convenient when the API returns JSON'''

'''
response.json()

# import requests module
import requests

# Making a get request
response = requests.get('https://api.github.com')

# print response
print(response)

# print json content
print(response.json())

'''

import requests,json
api_key="YOUR_API_KEY"
base_url="http://api.openweathermap.org/data/2.5/weather ?"
city_name=input("enter city name:")
complete_url=base_url+"appid="+api_key+"&q="+city_name
response=requests.get(complete_url)
x=response.json()
if x["cod"]!="404":
y=x["main"]
current_temperature=y["temp"]
current_pressure=y["pressure"]
current_humidity=y["humidity"]
z=x["weather"]

weather_description=z[0]["description"]
print("Temperature (in kelvin unit)= "+str(current_temperature) +
"\n atmospheric pressure(in hPa unit=" +str(current_pressure) +
"\n humidity (in percentage)=" +str(current_humidity) +
"\n description = "+str(weather_description))

else:
print("city not found")

Comments

Popular posts from this blog

java chapter11 practice question on abstruct class and interfaces

DAY 12 -AZURE DP900(Microsoft Azure Data Fundamentals: Explore non-relational data in Azure)

java exercise4