File size: 4,876 Bytes
35169b9
 
 
 
 
 
 
 
 
6ae965f
 
 
 
 
 
 
 
 
 
 
a911d0e
f6d2c53
 
 
 
ab6367f
 
 
 
f6d2c53
 
ab6367f
 
 
 
 
 
a911d0e
 
 
 
 
 
 
 
 
 
 
 
 
 
f6d2c53
 
 
a911d0e
ab6367f
 
 
 
 
 
 
 
 
f6d2c53
 
 
 
 
 
32d4420
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a911d0e
 
 
 
 
 
32d4420
35169b9
99330ba
b334288
99330ba
 
 
87fee95
35169b9
a911d0e
f6d2c53
 
 
 
 
 
 
ab6367f
 
f6d2c53
 
 
 
 
 
ab6367f
 
f6d2c53
 
 
a911d0e
 
 
 
 
 
 
 
87fee95
 
 
 
 
6ae965f
 
99330ba
 
 
 
 
35169b9
 
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
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 = """
<style>
body {
    color: orange;
    background-color: black;
}
</style>
"""
st.markdown(custom_css, unsafe_allow_html=True)

# Prescribed limits for AQI, PM2.5, PM10, and temperature
PRESCRIBED_LIMITS = {
    'AQI': {
        'good': (0, 50),
        'moderate': (51, 100),
        'unhealthy_sensitive': (101, 150),
        'unhealthy': (151, 200),
        'very_unhealthy': (201, 300),
        'hazardous': (301, 500)
    },
    'PM2.5': {
        'good': (0, 12.0),
        'moderate': (12.1, 35.4),
        'unhealthy_sensitive': (35.5, 55.5),
        'unhealthy': (55.6, 150.4),
        'very_unhealthy': (150.5, 250.4),
        'hazardous': (250.5, float('inf'))
    },
    'PM10': {
        'good': (0, 50),
        'moderate': (51, 100),
        'unhealthy_sensitive': (101, 250),
        'unhealthy': (251, 350),
        'very_unhealthy': (351, 430),
        'hazardous': (431, float('inf'))
    },
    'Temperature': {
        'comfortable': (0, 25),
        'moderate': (26, 30),
        'warm': (31, 35),
        'hot': (36, float('inf'))
    }
}

# Color codes for different AQI, PM2.5, PM10, and temperature levels
COLOR_CODES = {
    'good': 'green',
    'moderate': 'yellow',
    'unhealthy_sensitive': 'orange',
    'unhealthy': 'red',
    'very_unhealthy': 'purple',
    'hazardous': 'maroon'
}

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])
    aqi_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 = float(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 = float(line[pm10_start:pm10_end].strip())

    # Extract temperature value
    temp_start = line.find("temperature (") + len("temperature (")
    temp_end = line.find("˚C)", temp_start)
    temp = float(line[temp_start:temp_end].strip())

    return aqi, aqi_level, pm25, pm10, temp

def main():
    # Logo
    logo = 'LOGO.png'
    st.image(logo, width=200)

    st.title('Real Time SXR AQI Dashboard')
    st.subheader(f'Real-time Air Quality Monitoring - {datetime.datetime.now(indian_timezone).strftime("%Y-%m-%d %H:%M:%S")}')  # Displaying date and time

    aqi, aqi_level, pm25, pm10, temp = 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}")
        color_code = COLOR_CODES[aqi_safety]
        st.markdown(f'<p style="color:{color_code};">The AQI level is {aqi_safety}.</p>', 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}")
        color_code = COLOR_CODES[pm25_safety]
        st.markdown(f'<p style="color:{color_code};">The PM2.5 level is {pm25_safety}.</p>', 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}")
        color_code = COLOR_CODES[pm10_safety]
        st.markdown(f'<p style="color:{color_code};">The PM10 level is {pm10_safety}.</p>', unsafe_allow_html=True)

    # Display temperature with safety level
    st.write(f"- **Temperature:** {temp}˚C")
    temp_safety = check_safety_level(temp, 'Temperature')
    if temp_safety:
        st.write(f"Safety Level: {temp_safety}")
        color_code = COLOR_CODES[temp_safety]
        st.markdown(f'<p style="color:{color_code};">The temperature level is {temp_safety}.</p>', 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()