Neurolingua commited on
Commit
c74b0db
1 Parent(s): 9990a6c

Update other_function.py

Browse files
Files changed (1) hide show
  1. other_function.py +22 -37
other_function.py CHANGED
@@ -112,40 +112,25 @@ def get_weather(city):
112
  celcius=str(round((int(degree) - 32)* 5/9,1))+temperature[-2]+'C'
113
  return (celcius)
114
 
115
- def get_rates():
116
- chrome_options = Options()
117
- chrome_options.add_argument("--headless")
118
- chrome_options.add_argument("--no-sandbox")
119
- chrome_options.add_argument("--disable-dev-shm-usage")
120
- chrome_options.add_argument("--disable-gpu")
121
- chrome_options.add_argument("--disable-extensions")
122
- chrome_options.add_argument("--disable-infobars")
123
- chrome_options.add_argument("--disable-images")
124
- chrome_options.add_argument("--blink-settings=imagesEnabled=false") # Disable image loading
125
- chrome_options.add_argument("--enable-automation")
126
-
127
- # Initialize the WebDriver with the headless option
128
-
129
- driver = webdriver.Chrome(options=chrome_options)
130
-
131
- # Open the website
132
- driver.get('https://www.kisandeals.com/mandiprices/ALL/TAMIL-NADU/ALL')
133
-
134
- # Wait for the table to be present (instead of waiting for the entire page)
135
- table = WebDriverWait(driver, 5).until(
136
- EC.presence_of_element_located((By.XPATH, '//table'))
137
- )
138
-
139
- # Parse the table using pandas
140
- df = pd.read_html(table.get_attribute('outerHTML'))[0]
141
-
142
- # Drop the 'Quintal Price' column
143
- df.drop(columns=['Quintal Price'], inplace=True)
144
-
145
- # Convert the data to a dictionary
146
- d = {df.iloc[i, 0]: df.iloc[i, 1] for i in range(len(df))}
147
-
148
- # Close the WebDriver
149
- driver.quit()
150
-
151
- return str(d) + ' These prices are for 1 kg'
 
112
  celcius=str(round((int(degree) - 32)* 5/9,1))+temperature[-2]+'C'
113
  return (celcius)
114
 
115
+ import scrapy
116
+ from scrapy.selector import Selector
117
+ from urllib.parse import urljoin
118
+ import pandas as pd
119
+
120
+ class KisanDealsSpider(scrapy.Spider):
121
+ name = 'kisan_deals'
122
+ start_urls = ['https://www.kisandeals.com/mandiprices/ALL/TAMIL-NADU/ALL']
123
+
124
+ def parse(self, response):
125
+ table = response.xpath('//table')
126
+ rows = table.xpath('//tr')
127
+
128
+ data = []
129
+ for row in rows[1:]: # Skip the header row
130
+ crop = row.xpath('//td[1]/text()').get()
131
+ rate = row.xpath('//td[2]/text()').get()
132
+ data.append({'crop': crop, 'rate': rate})
133
+
134
+ df = pd.DataFrame(data)
135
+ df = df.drop(columns=['Quintal Price'])
136
+ return str(df.to_dict('index')) + ' These prices are for 1 kg'