-
Notifications
You must be signed in to change notification settings - Fork 0
/
maps.py
90 lines (67 loc) · 2.77 KB
/
maps.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import pandas as pd
import folium
import streamlit as st
from streamlit_folium import st_folium
import requests
from io import BytesIO
from PIL import Image
st.header("Select an Indian City and I will show it's Properties\n")
df = pd.read_csv('Indian Cities Database.csv')
df = df[['City','lat','lon']]
city_name = st.selectbox('''## Select any City''',(df.City.values))
df = df[df['City']==city_name]
api_key = '201af41b43acd8890a2b3fcb0cdb68a7'
weather_data = requests.get(f"https://api.openweathermap.org/data/2.5/weather?q={city_name}&units=imperial&APPID={api_key}")
#st.write(weather_data.json())
climate = (weather_data.json().get('weather','')[0].get('main',''))
cli_icon = (weather_data.json().get('weather','')[0].get('icon',''))
desc = (weather_data.json().get('weather','')[0].get('description',''))
lat = (weather_data.json().get('coord','').get('lat',''))
lon = (weather_data.json().get('coord','').get('lon',''))
wind_speed = (weather_data.json().get('wind','').get('speed',''))
temp = (weather_data.json().get('main','').get('temp',''))
hum = (weather_data.json().get('main','').get('humidity',''))
name = (weather_data.json().get('name',''))
data = pd.DataFrame({'city':name,'Weather':[climate],'description':[desc],'latitude':[lat],'longitude':[lon],
'temperature':str("{0:.3f}".format((temp - 32)*(5/9)))+' °C','humidity':str(hum)+'%'},index=['data'])
st.dataframe(data,width=900,use_container_width=True)
icon_url = f'https://openweathermap.org/img/w/{cli_icon}.png'
icon_response = requests.get(icon_url)
icon_content = icon_response.content
icon_bytesIO = BytesIO(icon_content)
st.write('''## Weather Condition ,temperature and humidity:''')
l,m,r = st.columns(3,gap='small')
with l:
st.write('''#### Weather Condition :''')
st.write('')
st.write('')
st.write('')
st.write('''#### Temperature(°C)''')
st.write('')
st.write('')
st.write('')
st.write('')
st.write('''#### Wind Speed(m/s)''')
st.write('')
st.write('')
st.write('')
st.write('''#### Humidity(%)''')
with m:
st.image(icon_bytesIO,width=100)
st.image('Temperature-Icon.png',width=50)
st.image('wind_speed.png',width=80)
st.image('hu.png',width=120)
with r:
st.header(f'{desc}')
st.write(' ')
st.write(' ')
st.header(str("{0:.2f}".format((temp - 32)*(5/9)))+' °C')
st.write('')
st.write('')
st.header(f'{wind_speed} m/s')
st.write(' ')
st.write(' ')
st.header(f'{hum}%')
m = folium.Map(location=[df.iloc[[0]].lat,df.iloc[[0]].lon],zoom_start=12)
folium.Marker([df.iloc[[0]].lat,df.iloc[[0]].lon],popup =df.iloc[[0]].City,tooltip=df.iloc[[0]].City).add_to(m)
st_data = st_folium(m, width=775)