Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please add CSS and other Aesthetics for my app.py code below: import streamlit as st import requests from streamlit _ folium import folium _ static
Please add CSS and other Aesthetics for my app.py code below:
import streamlit as st
import requests
from streamlitfolium import foliumstatic
import folium
import plotly.graphobjs as go
apikey "YOURAPIKEYHERE"
sttitleWeather and Air Quality Web App"
stheaderStreamlit and AirVisual API"
@stcachedata
def generatelistofcountries:
countriesurl "YOURAPIKEYHERE"
countriesdict requests.getcountriesurljson
return countriesdict
@stcachedata
def generatelistofstatescountryselected:
statesurl "YOURAPIKEYHERE"
statesdict requests.getstatesurljson
return statesdict
@stcachedata
def generatelistofcitiesstateselected, countryselected:
citiesurl "YOURAPIKEYHERE"
citiesdict requests.getcitiesurljson
return citiesdict
def displaydatadata:
stwriteTemperature: datacurrentweathertpdeg C
stwriteHumidity: datacurrentweatherhu
stwriteAir Quality Index AQI: datacurrentpollutionaqius
def mapcreatorlatitude longitude:
m folium.Maplocationlatitude longitude zoomstart
folium.Markerlatitude longitude popup"Location", tooltip"Location"addtom
foliumstaticm
category stselectboxSelect location method", By City, State, and Country", By Nearest City IP AddressBy Latitude and Longitude"
if category By City, State, and Country":
countriesdict generatelistofcountries
if countriesdictstatus "success":
countrieslist icountry for i in countriesdictdata
countrieslist.insert
countryselected stselectboxSelect a country", optionscountrieslist
if countryselected:
statesdict generatelistofstatescountryselected
if statesdictstatus "success":
stateslist istate for i in statesdictdata
stateslist.insert
stateselected stselectboxSelect a state", optionsstateslist
if stateselected:
citiesdict generatelistofcitiesstateselected, countryselected
if citiesdictstatus "success":
citieslist icity for i in citiesdictdata
citieslist.insert
cityselected stselectboxSelect a city", optionscitieslist
if cityselected:
aqidataurl "YOURAPIKEYHERE"
aqidatadict requests.getaqidataurljson
if aqidatadictstatus "success":
displaydataaqidatadictdata
mapcreatoraqidatadictdatalocationcoordinates aqidatadictdatalocationcoordinates
else:
stwarningNo data available for this location."
else:
stwarningNo cities available, please select another state."
else:
stwarningNo states available, please select another country."
else:
sterrorToo many requests. Wait for a few minutes before your next API call."
elif category By Nearest City IP Address:
url "YOURAPIKEYHERE" requests.geturljson
if aqidatadictstatus "success":
displaydataaqidatadictdata
mapcreatoraqidatadictdatalocationcoordinates aqidatadictdatalocationcoordinates
else:
stwarningNo data available for this location."
elif category By Latitude and Longitude":
latitude sttextinputEnter latitude"
longitude sttextinputEnter longitude"
if latitude and longitude:
url "YOURAPIKEYHERE"
aqidatadict requests.geturljson
if aqidatadictstatus "success":
displaydataaqidatadictdata
mapcreatoraqidatadictdatalocationcoordinates aqidatadictdatalocationcoordinates
else:
stwarningNo data available for this location."
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started