adil9858 commited on
Commit
35169b9
1 Parent(s): 3e3c89d

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +63 -0
app.py ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import requests
3
+ from bs4 import BeautifulSoup
4
+ import datetime
5
+ import pytz
6
+
7
+ # Set the timezone to Indian Standard Time (IST)
8
+ indian_timezone = pytz.timezone('Asia/Kolkata')
9
+
10
+ def get_aqi_data():
11
+ url = 'https://www.aqi.in/dashboard/india/jammu-and-kashmir/srinagar'
12
+ r = requests.get(url)
13
+ soup = BeautifulSoup(r.text, 'html.parser')
14
+ meta_tag = soup.find('meta', {'name': 'description'})
15
+ line = meta_tag['content']
16
+
17
+ # Extract AQI value
18
+ aqi_start = line.find("AQI) is") + len("AQI) is")
19
+ aqi_end = line.find(" level")
20
+ aqi = line[aqi_start:aqi_end].strip().split()[0]
21
+ level = line[aqi_start:aqi_end].strip().split()[1]
22
+
23
+ # Extract PM2.5 value
24
+ pm25_start = line.find("PM2.5 (") + len("PM2.5 (")
25
+ pm25_end = line.find(" µg/m³)", pm25_start)
26
+ pm25 = line[pm25_start:pm25_end].strip()
27
+
28
+ # Extract PM10 value
29
+ pm10_start = line.find("PM10 (") + len("PM10 (")
30
+ pm10_end = line.find(" µg/m³)", pm10_start)
31
+ pm10 = line[pm10_start:pm10_end].strip()
32
+
33
+ # Extract temperature value
34
+ temp_start = line.find("temperature (") + len("temperature (")
35
+ temp_end = line.find("˚C)", temp_start)
36
+ temp = line[temp_start:temp_end].strip()
37
+
38
+ return aqi, level, temp, pm25, pm10
39
+
40
+ def main():
41
+ st.title('Futuristic AQI Dashboard')
42
+ st.subheader('Real-time Air Quality Monitoring')
43
+
44
+ aqi, level, temp, pm25, pm10 = get_aqi_data()
45
+
46
+ st.markdown('### Current Data:')
47
+ st.write(f"- **AQI:** {aqi} ({level})")
48
+ st.write(f"- **PM2.5:** {pm25} µg/m³")
49
+ st.write(f"- **PM10:** {pm10} µg/m³")
50
+ st.write(f"- **Temperature:** {temp}˚C")
51
+
52
+ st.markdown('### Display Data in Buttons:')
53
+ if st.button('Show AQI'):
54
+ st.write(f"**AQI:** {aqi} ({level})")
55
+ if st.button('Show PM2.5'):
56
+ st.write(f"**PM2.5:** {pm25} µg/m³")
57
+ if st.button('Show PM10'):
58
+ st.write(f"**PM10:** {pm10} µg/m³")
59
+ if st.button('Show Temperature'):
60
+ st.write(f"**Temperature:** {temp}˚C")
61
+
62
+ if __name__ == '__main__':
63
+ main()