-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweather_py (1).py
34 lines (27 loc) · 1.39 KB
/
weather_py (1).py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# -*- coding: utf-8 -*-
"""weather.py
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1ykZjkrAzbISJBqnqrEeCdLhessUy2wYY
"""
import requests
#import os
from datetime import datetime
api_key = '50e4312140650c45ff6111052a993098'
location = input("Enter the city name: ")
complete_api_link = "https://api.openweathermap.org/data/2.5/weather?q="+location+"&appid="+api_key
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 ("-------------------------------------------------------------",file=open("output.txt", "a"))
print ("Weather Stats for - {} || {}".format(location.upper(), date_time),file=open("output.txt", "a"))
print ("-------------------------------------------------------------",file=open("output.txt", "a"))
print ("Current temperature is: {:.2f} deg C".format(temp_city),file=open("output.txt", "a"))
print ("Current weather desc :",weather_desc,file=open("output.txt", "a"))
print ("Current Humidity :",hmdt, '%',file=open("output.txt", "a"))
print ("Current wind speed :",wind_spd ,'kmph',file=open("output.txt", "a"))