Spaces:
Sleeping
Sleeping
Neurolingua
commited on
Commit
•
6ae465f
1
Parent(s):
2975b11
Update other_function.py
Browse files- other_function.py +32 -25
other_function.py
CHANGED
@@ -105,32 +105,39 @@ def get_weather(city):
|
|
105 |
return (celcius)
|
106 |
|
107 |
def get_rates():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
108 |
|
109 |
-
|
110 |
-
|
111 |
-
"https": "http://160.86.242.23:8080",
|
112 |
-
}
|
113 |
|
114 |
-
|
115 |
-
|
|
|
|
|
116 |
|
117 |
-
#
|
118 |
-
|
119 |
|
120 |
-
#
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
d = {}
|
131 |
-
for i in range(len(df)):
|
132 |
-
d[df.iloc[i, 0]] = df.iloc[i, 1]
|
133 |
-
|
134 |
-
return str(d) + ' These prices are for 1 kg'
|
135 |
-
else:
|
136 |
-
return get_rates()
|
|
|
105 |
return (celcius)
|
106 |
|
107 |
def get_rates():
|
108 |
+
chrome_options = Options()
|
109 |
+
chrome_options.add_argument("--headless")
|
110 |
+
chrome_options.add_argument("--no-sandbox")
|
111 |
+
chrome_options.add_argument("--disable-dev-shm-usage")
|
112 |
+
chrome_options.add_argument("--disable-gpu")
|
113 |
+
chrome_options.add_argument("--disable-extensions")
|
114 |
+
chrome_options.add_argument("--disable-infobars")
|
115 |
+
chrome_options.add_argument("--disable-images")
|
116 |
+
chrome_options.add_argument("--blink-settings=imagesEnabled=false") # Disable image loading
|
117 |
+
chrome_options.add_argument("--enable-automation")
|
118 |
+
|
119 |
+
# Initialize the WebDriver with the headless option
|
120 |
+
driver = webdriver.Chrome(service=Service(), options=chrome_options)
|
121 |
+
|
122 |
|
123 |
+
# Open the website
|
124 |
+
driver.get('https://www.kisandeals.com/mandiprices/ALL/TAMIL-NADU/ALL')
|
|
|
|
|
125 |
|
126 |
+
# Wait for the table to be present (instead of waiting for the entire page)
|
127 |
+
table = WebDriverWait(driver, 5).until(
|
128 |
+
EC.presence_of_element_located((By.XPATH, '//table'))
|
129 |
+
)
|
130 |
|
131 |
+
# Parse the table using pandas
|
132 |
+
df = pd.read_html(table.get_attribute('outerHTML'))[0]
|
133 |
|
134 |
+
# Drop the 'Quintal Price' column
|
135 |
+
df.drop(columns=['Quintal Price'], inplace=True)
|
136 |
+
|
137 |
+
# Convert the data to a dictionary
|
138 |
+
d = {df.iloc[i, 0]: df.iloc[i, 1] for i in range(len(df))}
|
139 |
+
|
140 |
+
# Close the WebDriver
|
141 |
+
driver.quit()
|
142 |
+
|
143 |
+
return str(d) + ' These prices are for 1 kg'
|
|
|
|
|
|
|
|
|
|
|
|
|
|