import streamlit as st import requests from bs4 import BeautifulSoup import datetime import pytz # Set the timezone to Indian Standard Time (IST) indian_timezone = pytz.timezone('Asia/Kolkata') # Custom CSS for styling custom_css = """ """ st.markdown(custom_css, unsafe_allow_html=True) # Prescribed limits for AQI, PM2.5, and PM10 PRESCRIBED_LIMITS = { 'AQI': { 'good': (0, 50), 'moderate': (51, 100), 'poor': (101, 200), 'very_poor': (201, 300), 'severe': (301, 500) }, 'PM2.5': { 'safe': (0, 30), 'moderate': (31, 60), 'poor': (61, 90), 'very_poor': (91, 120), 'severe': (121, 250) }, 'PM10': { 'safe': (0, 50), 'moderate': (51, 100), 'poor': (101, 250), 'very_poor': (251, 350), 'severe': (351, 430) } } def check_safety_level(value, parameter): for level, limits in PRESCRIBED_LIMITS[parameter].items(): if limits[0] <= value <= limits[1]: return level return None 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'] # Extract AQI value aqi_start = line.find("AQI) is") + len("AQI) is") aqi_end = line.find(" level") aqi = int(line[aqi_start:aqi_end].strip().split()[0]) level = line[aqi_start:aqi_end].strip().split()[1] # Extract PM2.5 value pm25_start = line.find("PM2.5 (") + len("PM2.5 (") pm25_end = line.find(" µg/m³)", pm25_start) pm25 = int(line[pm25_start:pm25_end].strip()) # Extract PM10 value pm10_start = line.find("PM10 (") + len("PM10 (") pm10_end = line.find(" µg/m³)", pm10_start) pm10 = int(line[pm10_start:pm10_end].strip()) return aqi, level, pm25, pm10 def main(): # Logo logo = 'LOGO.png' st.image(logo, width=200) st.title('Real Time SXR AQI Dashboard') st.subheader('Real-time Air Quality Monitoring') aqi, aqi_level, pm25, pm10 = get_aqi_data() # Display AQI with safety level st.markdown('### Current Data:') st.write(f"- **AQI:** {aqi} ({aqi_level})") aqi_safety = check_safety_level(aqi, 'AQI') if aqi_safety: st.write(f"Safety Level: {aqi_safety}") if aqi_safety == 'good': st.markdown('

The AQI level is safe.

', unsafe_allow_html=True) else: st.markdown('

The AQI level is unsafe.

', unsafe_allow_html=True) # Display PM2.5 with safety level st.write(f"- **PM2.5:** {pm25} µg/m³") pm25_safety = check_safety_level(pm25, 'PM2.5') if pm25_safety: st.write(f"Safety Level: {pm25_safety}") if pm25_safety == 'safe': st.markdown('

The PM2.5 level is safe.

', unsafe_allow_html=True) else: st.markdown('

The PM2.5 level is unsafe.

', unsafe_allow_html=True) # Display PM10 with safety level st.write(f"- **PM10:** {pm10} µg/m³") pm10_safety = check_safety_level(pm10, 'PM10') if pm10_safety: st.write(f"Safety Level: {pm10_safety}") if pm10_safety == 'safe': st.markdown('

The PM10 level is safe.

', unsafe_allow_html=True) else: st.markdown('

The PM10 level is unsafe.

', unsafe_allow_html=True) # Developer section st.markdown('### Developer:') st.text('Adil Aziz') st.text('Data Scientist') st.text('adilaziz2013@gmail.com') if __name__ == '__main__': main()