Neurolingua commited on
Commit
6af6472
1 Parent(s): b2bddc6

Update other_function.py

Browse files
Files changed (1) hide show
  1. other_function.py +23 -10
other_function.py CHANGED
@@ -105,13 +105,26 @@ def get_weather(city):
105
  return (celcius)
106
 
107
  def get_rates():
108
- r = requests.get(f'https://www.kisandeals.com/mandiprices/ALL/TAMIL-NADU/ALL')
109
- soup=BeautifulSoup(r.text,'html.parser')
110
- table= soup.find_all('table')
111
- df = pd.read_html(str(table))
112
- df=pd.DataFrame(df[0])
113
- df.drop(columns=['Quintal Price'],inplace=True)
114
- d={}
115
- for i in range(len(df)):
116
- d[df.iloc[i,0]]=df.iloc[i,1]
117
- return str(d)+' This prices are for 1 kg'
 
 
 
 
 
 
 
 
 
 
 
 
 
 
105
  return (celcius)
106
 
107
  def get_rates():
108
+ r = requests.get('https://www.kisandeals.com/mandiprices/ALL/TAMIL-NADU/ALL')
109
+ soup = BeautifulSoup(r.text, 'html.parser')
110
+
111
+ # Assuming the table you want is the first one
112
+ table = soup.find('table')
113
+
114
+ # Check if a table was found
115
+ if table:
116
+ # Convert the HTML table to a DataFrame
117
+ df = pd.read_html(str(table))[0]
118
+
119
+ # Dropping the 'Quintal Price' column
120
+ if 'Quintal Price' in df.columns:
121
+ df.drop(columns=['Quintal Price'], inplace=True)
122
+
123
+ # Creating a dictionary from the DataFrame
124
+ d = {}
125
+ for i in range(len(df)):
126
+ d[df.iloc[i, 0]] = df.iloc[i, 1]
127
+
128
+ return str(d) + ' These prices are for 1 kg'
129
+ else:
130
+ return "No table found on the page"