Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1145,7 +1145,6 @@ def fetch_and_store_data_market():
|
|
| 1145 |
latest_doc = market_price_data.find_one(sort=[("Reported Date", -1)])
|
| 1146 |
if latest_doc and "Reported Date" in latest_doc:
|
| 1147 |
latest_date = latest_doc["Reported Date"]
|
| 1148 |
-
st.write("Latest Date: ", latest_date)
|
| 1149 |
else:
|
| 1150 |
latest_date = None
|
| 1151 |
|
|
@@ -1158,14 +1157,11 @@ def fetch_and_store_data_market():
|
|
| 1158 |
to_date = (datetime.now() - timedelta(days=1)).strftime('%d %b %Y')
|
| 1159 |
from_date_obj = datetime.strptime(from_date, '%d %b %Y')
|
| 1160 |
to_date_obj = datetime.strptime(to_date, '%d %b %Y')
|
| 1161 |
-
st.write(to_date_obj)
|
| 1162 |
-
st.write(from_date_obj)
|
| 1163 |
|
| 1164 |
if to_date_obj <= from_date_obj:
|
| 1165 |
st.write("Data already scraped")
|
| 1166 |
return None
|
| 1167 |
base_url = "https://agmarknet.gov.in/SearchCmmMkt.aspx"
|
| 1168 |
-
st.write(base_url)
|
| 1169 |
params = {
|
| 1170 |
"Tx_Commodity": "11",
|
| 1171 |
"Tx_State": "0",
|
|
@@ -1191,16 +1187,12 @@ def fetch_and_store_data_market():
|
|
| 1191 |
}
|
| 1192 |
|
| 1193 |
response = requests.get(api_url, params=scraperapi_params)
|
| 1194 |
-
st.write("Response: ", response.status_code)
|
| 1195 |
if response.status_code == 200:
|
| 1196 |
soup = BeautifulSoup(response.content, 'html.parser')
|
| 1197 |
if soup:
|
| 1198 |
-
st.write("Got html content")
|
| 1199 |
-
st.write(soup.contents)
|
| 1200 |
table = soup.find("table", {"class": "tableagmark_new"})
|
| 1201 |
if table:
|
| 1202 |
headers = [th.get_text(strip=True) for th in table.find_all("th")]
|
| 1203 |
-
st.write("Got all headers")
|
| 1204 |
rows = []
|
| 1205 |
|
| 1206 |
for row in table.find_all("tr")[1:]:
|
|
@@ -1325,7 +1317,6 @@ if st.session_state.authenticated:
|
|
| 1325 |
st.title("🌾 AgriPredict Dashboard")
|
| 1326 |
if st.button("Get Live Data Feed"):
|
| 1327 |
fetch_and_store_data()
|
| 1328 |
-
st.write("Now executing Market scraper: ")
|
| 1329 |
fetch_and_store_data_market()
|
| 1330 |
view_mode = st.radio("", ["Statistics", "Plots", "Predictions", "Exim"], horizontal=True)
|
| 1331 |
|
|
|
|
| 1145 |
latest_doc = market_price_data.find_one(sort=[("Reported Date", -1)])
|
| 1146 |
if latest_doc and "Reported Date" in latest_doc:
|
| 1147 |
latest_date = latest_doc["Reported Date"]
|
|
|
|
| 1148 |
else:
|
| 1149 |
latest_date = None
|
| 1150 |
|
|
|
|
| 1157 |
to_date = (datetime.now() - timedelta(days=1)).strftime('%d %b %Y')
|
| 1158 |
from_date_obj = datetime.strptime(from_date, '%d %b %Y')
|
| 1159 |
to_date_obj = datetime.strptime(to_date, '%d %b %Y')
|
|
|
|
|
|
|
| 1160 |
|
| 1161 |
if to_date_obj <= from_date_obj:
|
| 1162 |
st.write("Data already scraped")
|
| 1163 |
return None
|
| 1164 |
base_url = "https://agmarknet.gov.in/SearchCmmMkt.aspx"
|
|
|
|
| 1165 |
params = {
|
| 1166 |
"Tx_Commodity": "11",
|
| 1167 |
"Tx_State": "0",
|
|
|
|
| 1187 |
}
|
| 1188 |
|
| 1189 |
response = requests.get(api_url, params=scraperapi_params)
|
|
|
|
| 1190 |
if response.status_code == 200:
|
| 1191 |
soup = BeautifulSoup(response.content, 'html.parser')
|
| 1192 |
if soup:
|
|
|
|
|
|
|
| 1193 |
table = soup.find("table", {"class": "tableagmark_new"})
|
| 1194 |
if table:
|
| 1195 |
headers = [th.get_text(strip=True) for th in table.find_all("th")]
|
|
|
|
| 1196 |
rows = []
|
| 1197 |
|
| 1198 |
for row in table.find_all("tr")[1:]:
|
|
|
|
| 1317 |
st.title("🌾 AgriPredict Dashboard")
|
| 1318 |
if st.button("Get Live Data Feed"):
|
| 1319 |
fetch_and_store_data()
|
|
|
|
| 1320 |
fetch_and_store_data_market()
|
| 1321 |
view_mode = st.radio("", ["Statistics", "Plots", "Predictions", "Exim"], horizontal=True)
|
| 1322 |
|