Spaces:
Runtime error
Runtime error
Chintan Donda
commited on
Commit
•
be4bdc0
1
Parent(s):
1921a14
Crawling State and their Codes for Weather forecast
Browse files- app.py +1 -1
- src/constants.py +1 -41
- src/weather.py +10 -11
app.py
CHANGED
@@ -381,7 +381,7 @@ with gr.Blocks(title='KKMS-KSSW Demo') as demo:
|
|
381 |
with gr.Tab(label='Weather Forecast for next 5 days'):
|
382 |
# Select the State
|
383 |
state = gr.Dropdown(
|
384 |
-
constants_utils.
|
385 |
label="Select state"
|
386 |
)
|
387 |
|
|
|
381 |
with gr.Tab(label='Weather Forecast for next 5 days'):
|
382 |
# Select the State
|
383 |
state = gr.Dropdown(
|
384 |
+
list(constants_utils.WEATHER_FORECAST_STATE_CODES.keys()),
|
385 |
label="Select state"
|
386 |
)
|
387 |
|
src/constants.py
CHANGED
@@ -124,47 +124,7 @@ MANDI_PRICE_STATES = [
|
|
124 |
|
125 |
# State list used in the Weather forecast widget dropdown list
|
126 |
weather_utils_obj = weather_utils.WEATHER()
|
127 |
-
|
128 |
-
|
129 |
-
WEATHER_FORECAST_STATE_CODES = {
|
130 |
-
'Andaman-Nicobar': '01',
|
131 |
-
'Andhra-Pradesh': '02',
|
132 |
-
'Arunachal-Pradesh': '03',
|
133 |
-
'Assam': '04',
|
134 |
-
'Bihar': '05',
|
135 |
-
'Chandigarh': '06',
|
136 |
-
'Chhattisgarh': '07',
|
137 |
-
'Dadra-and-Nagar-Haveli': '08',
|
138 |
-
'Daman-and-Diu': '09',
|
139 |
-
'Delhi': '10',
|
140 |
-
'Goa': '11',
|
141 |
-
'Gujarat': '12',
|
142 |
-
'Haryana': '13',
|
143 |
-
# 14
|
144 |
-
'Himachal-Pradesh': '15',
|
145 |
-
'Jammu-Kashmir': '16',
|
146 |
-
'Jharkhand': '17',
|
147 |
-
'Karnataka': '18',
|
148 |
-
'Kerala': '19',
|
149 |
-
'Lakshadweep': '20',
|
150 |
-
'Madhya-Pradesh': '21',
|
151 |
-
'Maharashtra': '22',
|
152 |
-
'Manipur': '23',
|
153 |
-
'Meghalaya': '24',
|
154 |
-
'Mizoram': '25',
|
155 |
-
'Nagaland': '26',
|
156 |
-
'Odisha': '27',
|
157 |
-
'Pondicherry': '28',
|
158 |
-
'Punjab': '29',
|
159 |
-
'Rajasthan': '30',
|
160 |
-
'Sikkim': '31',
|
161 |
-
'Tamilnadu': '32',
|
162 |
-
'Telangana': '33',
|
163 |
-
'Tripura': '34',
|
164 |
-
'Uttar-Pradesh': '35',
|
165 |
-
'Uttarakhand': '36',
|
166 |
-
'West-Bengal': '37',
|
167 |
-
}
|
168 |
|
169 |
# LIST OF PESTICIDES WHICH ARE BANNED AND RESTRICTED USE (List created from: https://pib.gov.in/PressReleaseIframePage.aspx?PRID=1896140)
|
170 |
BANNED_PESTICIDES_FORMULATIONS = [
|
|
|
124 |
|
125 |
# State list used in the Weather forecast widget dropdown list
|
126 |
weather_utils_obj = weather_utils.WEATHER()
|
127 |
+
WEATHER_FORECAST_STATE_CODES = weather_utils_obj.get_state_names_codes()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
128 |
|
129 |
# LIST OF PESTICIDES WHICH ARE BANNED AND RESTRICTED USE (List created from: https://pib.gov.in/PressReleaseIframePage.aspx?PRID=1896140)
|
130 |
BANNED_PESTICIDES_FORMULATIONS = [
|
src/weather.py
CHANGED
@@ -6,18 +6,15 @@ import src.constants as constants_utils
|
|
6 |
class WEATHER:
|
7 |
def __init__(self):
|
8 |
self.base_url = 'https://nwp.imd.gov.in/blf/blf_temp'
|
9 |
-
|
10 |
-
self.states = []
|
11 |
-
self.districts = []
|
12 |
-
self.states_districts = dict(
|
13 |
-
(ds, None) for ds in list(constants_utils.DATA_SOURCES.values()))
|
14 |
-
|
15 |
self.headers = {
|
16 |
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
|
17 |
}
|
18 |
|
|
|
|
|
|
|
19 |
|
20 |
-
def
|
21 |
self
|
22 |
):
|
23 |
response = requests.get(
|
@@ -26,9 +23,12 @@ class WEATHER:
|
|
26 |
)
|
27 |
|
28 |
soup = bs(response.text, 'html.parser')
|
29 |
-
|
30 |
-
|
31 |
-
|
|
|
|
|
|
|
32 |
|
33 |
|
34 |
def get_district_names(
|
@@ -44,7 +44,6 @@ class WEATHER:
|
|
44 |
soup = bs(response.text, 'html.parser')
|
45 |
self.districts = soup.findAll('select', {'name': 'dis'}, limit=None)
|
46 |
self.districts = [district.strip() for district in self.districts[0].text.split('\n') if district and district != 'Select']
|
47 |
-
# self.districts = [district for district in self.districts[0].text.split('\n\n') if district]
|
48 |
return self.districts
|
49 |
|
50 |
|
|
|
6 |
class WEATHER:
|
7 |
def __init__(self):
|
8 |
self.base_url = 'https://nwp.imd.gov.in/blf/blf_temp'
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
self.headers = {
|
10 |
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
|
11 |
}
|
12 |
|
13 |
+
self.state_names_codes = {}
|
14 |
+
self.districts = []
|
15 |
+
|
16 |
|
17 |
+
def get_state_names_codes(
|
18 |
self
|
19 |
):
|
20 |
response = requests.get(
|
|
|
23 |
)
|
24 |
|
25 |
soup = bs(response.text, 'html.parser')
|
26 |
+
for option in soup.find_all('option'):
|
27 |
+
if option.text.strip() == 'Select':
|
28 |
+
continue
|
29 |
+
self.state_names_codes[option.text.strip()] = str(option['value'].split('=')[-1][:2])
|
30 |
+
|
31 |
+
return self.state_names_codes
|
32 |
|
33 |
|
34 |
def get_district_names(
|
|
|
44 |
soup = bs(response.text, 'html.parser')
|
45 |
self.districts = soup.findAll('select', {'name': 'dis'}, limit=None)
|
46 |
self.districts = [district.strip() for district in self.districts[0].text.split('\n') if district and district != 'Select']
|
|
|
47 |
return self.districts
|
48 |
|
49 |
|