Skip to content
24 changes: 24 additions & 0 deletions APIScripts/OpenWeatherMap API/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# 🌤️ OpenWeatherMap API ⛈️
OpenWeatherMap is an online service that provides global weather data via API, including current weather data, forecasts, nowcasts and historical weather data for any geographical location.

The APIs support multiple languages, units of measurement and industry standard data formats like JSON and XML.


# :page_facing_up: Source
![openweathermap](https://user-images.githubusercontent.com/83420185/119532530-99588900-bda2-11eb-9c3f-955614f66e8b.png)

# :computer: Output

### 1st Case
Checking weather details for **Noida**

![pro](https://user-images.githubusercontent.com/83420185/119536646-ef2f3000-bda6-11eb-9213-e2145404c172.png)

### 2nd Case
Checking weather details for **London**

![pro1](https://user-images.githubusercontent.com/83420185/119536661-f22a2080-bda6-11eb-9832-108bdbafe611.png)




39 changes: 39 additions & 0 deletions APIScripts/OpenWeatherMap API/weather.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# fetching weather details of any particular city using OpenWeatherMap API

import requests
import time

try:
city = input("Enter the city name--")
# create and use your own appid
api = "http://api.openweathermap.org/data/2.5/weather?q=" + city + "&appid=<put-your-appid-here>"
w_data = requests.get(api).json()

weather = w_data['weather'][0]['main']
temp = int(w_data['main']['temp'] - 273.15)
temp_min = int(w_data['main']['temp_min'] - 273.15)
temp_max = int(w_data['main']['temp_max'] - 273.15)

pressure = w_data['main']['pressure']
humidity = w_data['main']['humidity']
visibility = w_data['visibility']

wind = w_data['wind']['speed']
sunrise = time.strftime("%H:%M:%S", time.gmtime(w_data['sys']['sunrise'] + 19800))
sunset = time.strftime("%H:%M:%S", time.gmtime(w_data['sys']['sunset'] + 19800))

all_data1 = f"Weather condition: {weather} \nTemperature: {str(temp)}°C\n"
all_data2 = f"Minimum Temperature: {str(temp_min)}°C \n" \
f"Maximum Temperature: {str(temp_max)}°C \n" \
f"Pressure: {str(pressure)} millibar \n" \
f"Humidity: {str(humidity)}% \n\n" \
f"Visibility: {str(visibility)} metres \n" \
f"Wind: {str(wind)} km/hr \nSunrise: {sunrise} " \
f"\nSunset: {sunset}"
print(f"Weather information for {city.capitalize()}...")
print(all_data1)
print(all_data2)

except Exception as e:
pass

1 change: 1 addition & 0 deletions APIScripts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
API Scripts is a collection of scripts/projects using any API for performing any specific task, it useful for those who have basic programming knowledge in python