Home » Python projects » Python project – weather info via API

Python project – weather info via API

weather api python

About Project

Receive current weather information of any place using openweather api

In this Python project, you will learn to write a python app that will collect weather information such as current temperature, pressure, humidity, wind speed, weather description and many others, of any place on the earth, using OpenWeatherMap API. This project is going to be very short and simple. You need to invest 30 min to understand everything.

You can find these weather information in real time by just typing the city name. You will be able to get the data about only those places which are listed (or supported) by OpenWeatherMap website.

python project list by aipython

Project requirements

  • Python version 3.6 and above (although lower version should also work)
  • Python requests module should be installed
  • Free account on OpenWeatherMap and api access token

Python code


import requests
import os
from datetime import datetime

user_api = os.environ['current_weather_data']
location = input("Enter the city name: ")

complete_api_link = "https://api.openweathermap.org/data/2.5/weather?q="+location+"&appid="+user_api
api_link = requests.get(complete_api_link)
api_data = api_link.json()

#create variables to store and display data
temp_city = ((api_data['main']['temp']) - 273.15)
weather_desc = api_data['weather'][0]['description']
hmdt = api_data['main']['humidity']
wind_spd = api_data['wind']['speed']
date_time = datetime.now().strftime("%d %b %Y | %I:%M:%S %p")

print ("-------------------------------------------------------------")
print ("Weather Stats for - {}  || {}".format(location.upper(), date_time))
print ("-------------------------------------------------------------")

print ("Current temperature is: {:.2f} deg C".format(temp_city))
print ("Current weather desc  :",weather_desc)
print ("Current Humidity      :",hmdt, '%')
print ("Current wind speed    :",wind_spd ,'kmph')

3 thoughts on “Python project – weather info via API”

  1. Pingback: "API Python ile hava durumu verilerini alma" kodu Cevap - Kod Yanıtları

How did you like the content

Scroll to Top