|
import streamlit as st |
|
import requests |
|
from bs4 import BeautifulSoup |
|
import datetime |
|
import pytz |
|
|
|
|
|
indian_timezone = pytz.timezone('Asia/Kolkata') |
|
|
|
def get_aqi_data(): |
|
url = 'https://www.aqi.in/dashboard/india/jammu-and-kashmir/srinagar' |
|
r = requests.get(url) |
|
soup = BeautifulSoup(r.text, 'html.parser') |
|
meta_tag = soup.find('meta', {'name': 'description'}) |
|
line = meta_tag['content'] |
|
|
|
|
|
aqi_start = line.find("AQI) is") + len("AQI) is") |
|
aqi_end = line.find(" level") |
|
aqi = line[aqi_start:aqi_end].strip().split()[0] |
|
level = line[aqi_start:aqi_end].strip().split()[1] |
|
|
|
|
|
pm25_start = line.find("PM2.5 (") + len("PM2.5 (") |
|
pm25_end = line.find(" µg/m³)", pm25_start) |
|
pm25 = line[pm25_start:pm25_end].strip() |
|
|
|
|
|
pm10_start = line.find("PM10 (") + len("PM10 (") |
|
pm10_end = line.find(" µg/m³)", pm10_start) |
|
pm10 = line[pm10_start:pm10_end].strip() |
|
|
|
|
|
temp_start = line.find("temperature (") + len("temperature (") |
|
temp_end = line.find("˚C)", temp_start) |
|
temp = line[temp_start:temp_end].strip() |
|
|
|
return aqi, level, temp, pm25, pm10 |
|
|
|
def main(): |
|
st.title('Futuristic AQI Dashboard') |
|
st.subheader('Real-time Air Quality Monitoring') |
|
|
|
aqi, level, temp, pm25, pm10 = get_aqi_data() |
|
|
|
st.markdown('### Current Data:') |
|
st.write(f"- **AQI:** {aqi} ({level})") |
|
st.write(f"- **PM2.5:** {pm25} µg/m³") |
|
st.write(f"- **PM10:** {pm10} µg/m³") |
|
st.write(f"- **Temperature:** {temp}˚C") |
|
|
|
st.markdown('### Display Data in Buttons:') |
|
if st.button('Show AQI'): |
|
st.write(f"**AQI:** {aqi} ({level})") |
|
if st.button('Show PM2.5'): |
|
st.write(f"**PM2.5:** {pm25} µg/m³") |
|
if st.button('Show PM10'): |
|
st.write(f"**PM10:** {pm10} µg/m³") |
|
if st.button('Show Temperature'): |
|
st.write(f"**Temperature:** {temp}˚C") |
|
|
|
if __name__ == '__main__': |
|
main() |
|
|