Da-Rabbit-Hole commited on
Commit
a96c9cc
·
verified ·
1 Parent(s): 23fb26e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +77 -79
app.py CHANGED
@@ -109,103 +109,104 @@ def get_weather_data(city: str):
109
  print(f"The warmest city is {warmest_city} with an average of {avg_temps[warmest_city]:.1f}°C")
110
 
111
 
112
-
113
-
114
-
115
  @tool
116
- def hotel_recommendation_tool(city: str,price: str): str
117
- """This is a hotel recommendation tool that web scrapes foursquare.com, and yelp.com for hotel ratings, user comments, and hotel information.
118
- Args:
119
- city: A string representing a valid city (e.g., 'Dubai, Singapore')
120
- Args:
121
- price: A string representing a valid price for the hotel rooms (e.g., '$160/night, $100/day')
122
-
123
- Returns: A hotel name in a particular city with its pricing, and rating information
124
- """
 
125
 
126
- if(price!="-"):
127
- response=ur.request.urlopen('https://foursquare.com/explore?mode=url&near='+city+'&price='+price+'&q=Resturant')
128
- else:
129
- response=ur.request.urlopen('https://foursquare.com/explore?mode=url&near='+city+'&q=Resturant')
130
- html=response.read()
131
- soup=BeautifulSoup(html,'html.parser')
132
- name=[]
133
- rate=[]
134
- add=[]
135
- y="""<li class="card singleRecommendation hasPhoto"""
136
- for link in soup.find_all('li'):
137
- if (y in str(link)):
138
- name.append(link.find('div',{"class":"venueName"}))
139
- if(link.find('div',{"class":"venueScore positive"})!=None):
140
- rate.append(link.find('div',{"class":"venueScorepositive"}))
141
- elif(link.find('div',{"class":"venueScoreneutral"})!=None):
142
- rate.append(link.find('div',{"class":"venueScoreneutral"}))
143
- else:
144
- rate.append(link.find('div',{"class":"venueScoreunknown"}))
145
-
146
- rate1=[]
147
- for x in rate:
148
- if(x!=None):
149
- rate1.append(x.string.encode("utf-8"))
 
 
 
150
  else:
151
  rate1.append("?")
152
-
153
- ##print(rate1)
154
-
155
- name1=[]
156
- for x in name:
157
- name1.append(x.a.string.encode("utf-8"))
158
-
159
- name_rate=[]
160
- for i in range(0,len(name1)):
161
- name_rate.append((name1[i],rate1[i]))
162
 
163
- return name_rate
 
 
 
 
 
 
 
 
164
 
165
 
166
-
167
- def yelp(city,price):
168
- name_rate=[]
169
- count=0
170
- while(count<30):
171
- if(price!="-"):
172
- response=ur.request.urlopen('https://www.yelp.com/search?find_desc=Restaurants&find_loc='+city+'&start='+str(count)+'&ed_attrs=RestaurantsPriceRange2.'+price)
173
  else:
174
- response=ur.request.urlopen('https://www.yelp.com/search?find_desc=Restaurants&find_loc='+city+'&start='+str(count))
175
-
176
- html=response.read()
177
- count+=10
178
- soup=BeautifulSoup(html,'html.parser')
 
 
 
 
 
 
179
 
180
- y="""<li class="regular-search-result">"""
181
- name=[]
182
- rate=[]
183
- name1=[]
184
- rate1=[]
185
  for link in soup.find_all('li'):
186
  if (y in str(link)):
187
- name.append(link.find('span',{"class":"indexed-bizname"}))
188
- rate.append(link.find('img',{"class":"offscreen"}))
 
189
  for i in name:
190
  name1.append(i.span.string.encode("utf-8"))
191
 
192
  for i in rate:
193
  try:
194
- s=str(i['alt'])
195
  rate1.append(float(s[0:3]))
196
  except:
197
  rate1.append("?")
198
- for i in range(0,len(name1)):
199
- name_rate.append((name1[i],rate1[i]))
200
 
201
- return name_rate
 
202
 
 
203
 
204
 
205
  root=tk.Tk()
206
  root.geometry("645x660")
207
  root.configure(bg='#211C5F')
208
  root.title("Scraping Recommender")
 
209
  def locate():
210
  send_url = 'http://freegeoip.net/json'
211
  r = requests.get(send_url)
@@ -217,7 +218,6 @@ def locate():
217
  e1.insert(tk.END,"Current Location")
218
  return city
219
 
220
-
221
  def get():
222
  city=e1.get()
223
  if(city=="Current Location"):
@@ -233,16 +233,14 @@ def get():
233
 
234
  @tool
235
  def SearchTool(DuckDuckGoSearchTool): query
236
-
237
- """
238
  name = "web_search"
239
  description = "Performs a web search for a query and returns a list of the top search results formatted as markdown with page titles and urls."
240
  inputs = {"query": {"type": "string", "description": "The search query to perform."}}
241
  output_type = "string"
242
- """
243
-
244
- search_tool = DuckDuckGoSearchTool()
245
- agent = CodeAgent(tools=[search_tool], model=model, add_base_tools=False, verbosity_level=2)
246
-
247
 
248
- GradioUI(agent).launch()
 
109
  print(f"The warmest city is {warmest_city} with an average of {avg_temps[warmest_city]:.1f}°C")
110
 
111
 
 
 
 
112
  @tool
113
+ def hotel_recommendation_tool(city: str, price: str) -> str:
114
+ """
115
+ This is a hotel recommendation tool that web scrapes foursquare.com and yelp.com for hotel ratings, user comments, and hotel information.
116
+ Args:
117
+ city: A string representing a valid city (e.g., 'Dubai, Singapore')
118
+ price: A string representing a valid price for the hotel rooms (e.g., '$160/night, $100/day')
119
+
120
+ Returns:
121
+ A hotel name in a particular city with its pricing and rating information
122
+ """
123
 
124
+ if price != "-":
125
+ response = ur.request.urlopen('https://foursquare.com/explore?mode=url&near=' + city + '&price=' + price + '&q=Resturant')
126
+ else:
127
+ response = ur.request.urlopen('https://foursquare.com/explore?mode=url&near=' + city + '&q=Resturant')
128
+
129
+ html = response.read()
130
+ soup = BeautifulSoup(html, 'html.parser')
131
+ name = []
132
+ rate = []
133
+ add = []
134
+ y = """<li class="card singleRecommendation hasPhoto\""""
135
+
136
+ for link in soup.find_all('li'):
137
+ if y in str(link):
138
+ name.append(link.find('div', {"class":"venueName"}))
139
+ if link.find('div', {"class":"venueScore positive"}) != None:
140
+ rate.append(link.find('div', {"class":"venueScorepositive"}))
141
+ elif link.find('div', {"class":"venueScore neutral"}) != None:
142
+ rate.append(link.find('div', {"class":"venueScoreneutral"}))
143
+ else:
144
+ rate.append(link.find('div', {"class":"venueScoreunknown"}))
145
+
146
+ rate1 = []
147
+
148
+ for x in rate:
149
+ if x != None:
150
+ rate1.append(x.string.encode("utf-8"))
151
  else:
152
  rate1.append("?")
 
 
 
 
 
 
 
 
 
 
153
 
154
+ name1 = []
155
+ for x in name:
156
+ name1.append(x.a.string.encode("utf-8"))
157
+
158
+ name_rate = []
159
+ for i in range(0, len(name1)):
160
+ name_rate.append((name1[i], rate1[i]))
161
+
162
+ return name_rate
163
 
164
 
165
+ def yelp(city, price):
166
+ name_rate = []
167
+ count = 0
168
+ while (count < 30):
169
+ if price != "-":
170
+ response = ur.request.urlopen('https://www.yelp.com/search?find_desc=Restaurants&find_loc=' + city + '&start=' + str(count) + '&ed_attrs=RestaurantsPriceRange2.' + price)
 
171
  else:
172
+ response = ur.request.urlopen('https://www.yelp.com/search?find_desc=Restaurants&find_loc=' + city + '&start=' + str(count))
173
+
174
+ html = response.read()
175
+ count += 10
176
+ soup = BeautifulSoup(html, 'html.parser')
177
+
178
+ y = """<li class="regular-search-result">"""
179
+ name = []
180
+ rate = []
181
+ name1 = []
182
+ rate1 = []
183
 
 
 
 
 
 
184
  for link in soup.find_all('li'):
185
  if (y in str(link)):
186
+ name.append(link.find('span', {"class":"indexed-bizname"}))
187
+ rate.append(link.find('img', {"class":"offscreen"}))
188
+
189
  for i in name:
190
  name1.append(i.span.string.encode("utf-8"))
191
 
192
  for i in rate:
193
  try:
194
+ s = str(i['alt'])
195
  rate1.append(float(s[0:3]))
196
  except:
197
  rate1.append("?")
 
 
198
 
199
+ for i in range(0, len(name1)):
200
+ name_rate.append((name1[i], rate1[i]))
201
 
202
+ return name_rate
203
 
204
 
205
  root=tk.Tk()
206
  root.geometry("645x660")
207
  root.configure(bg='#211C5F')
208
  root.title("Scraping Recommender")
209
+
210
  def locate():
211
  send_url = 'http://freegeoip.net/json'
212
  r = requests.get(send_url)
 
218
  e1.insert(tk.END,"Current Location")
219
  return city
220
 
 
221
  def get():
222
  city=e1.get()
223
  if(city=="Current Location"):
 
233
 
234
  @tool
235
  def SearchTool(DuckDuckGoSearchTool): query
236
+ """
 
237
  name = "web_search"
238
  description = "Performs a web search for a query and returns a list of the top search results formatted as markdown with page titles and urls."
239
  inputs = {"query": {"type": "string", "description": "The search query to perform."}}
240
  output_type = "string"
241
+ """
242
+
243
+ search_tool = DuckDuckGoSearchTool()
244
+ agent = CodeAgent(tools=[search_tool], model=model, add_base_tools=False, verbosity_level=2)
 
245
 
246
+ GradioUI(agent).launch()