Beispiel #1
0
def price_range_result():
	price=request.form['price']
	baseurl='https://api.yelp.com/v3/businesses/search'
	headers={'Authorization': 'Bearer %s' % secret.api_key}
	params={}
	params['location']=model.city_name
	params['price']=price
	results=model.make_request_using_cache(baseurl,headers,params)
	print(results)
	model.insert_table_from_api(results)
	conn = sqlite3.connect('final507.sqlite')
	cur = conn.cursor()
	statement='select r.lati,r.logi,r.name,r.id from restaurants_info as r join city_info as c on c.Id=r.city where r.price=? and c.name =? limit 20'
	if int(price)==1:
		the_price='$'
	elif int(price)==2:
		the_price='$$'
	elif int(price)==3:
		the_price='$$$'
	else:
		the_price='$$$$'
	print(the_price)
	cur.execute(statement,(the_price, model.city_name))
	result=cur.fetchall()
	data,layout=model.plot_prepare(result)
	fig = dict(data=data, layout=layout )
	my_plot_div = plot(fig, include_plotlyjs=False, output_type='div')
	statement='select * from city_info where name=?'
	cur.execute(statement,[model.city_name])
	city_information=cur.fetchone()
	conn.close()
	print(result)
	return render_template("price_range_visul.html", city_information=city_information, city_name=model.city_name, div_placeholder=Markup(my_plot_div))
Beispiel #2
0
 def test_access_api_through_price_range(self):
     baseurl='https://api.yelp.com/v3/businesses/search'
     headers={'Authorization': 'Bearer %s' % secret.api_key}
     params={}
     params['location']='Chicago'
     params['price']=2
     results=model.make_request_using_cache(baseurl,headers,params)
     self.assertEqual(results['businesses'][0]['location']['city'],'Chicago')
     self.assertEqual(results['businesses'][0]['price'],'$$')
Beispiel #3
0
 def test_access_api_through_open_now(self):
     baseurl='https://api.yelp.com/v3/businesses/search'
     headers={'Authorization': 'Bearer %s' % secret.api_key}
     params={}
     params['location']='Chicago'
     params['open_now']=True
     results=model.make_request_using_cache(baseurl,headers,params)
     self.assertEqual(results['businesses'][0]['location']['city'],'Chicago')
     self.assertEqual(results['businesses'][0]['is_closed'],False)
Beispiel #4
0
 def test_insert_table_from_open_now(self):
     model.init('Chicago')
     model.insert_table_from_scrap('Chicago')
     baseurl='https://api.yelp.com/v3/businesses/search'
     headers={'Authorization': 'Bearer %s' % secret.api_key}
     params={}
     params['location']='Chicago'
     params['open_now']=True
     results=model.make_request_using_cache(baseurl,headers,params)
     model.insert_table_from_api(results,'bars')
     conn = sqlite3.connect('final507.sqlite')
     cur = conn.cursor()
     statement='select * from restaurants_info where id=?'
     cur.execute(statement,[results['businesses'][0]['id']])
     result=cur.fetchone()
     self.assertEqual(results['businesses'][0]['id'],result[0])
     conn.commit()
     conn.close()
Beispiel #5
0
 def test_plot_prepare_type(self):
     model.init('Chicago')
     model.insert_table_from_scrap('Chicago')
     baseurl='https://api.yelp.com/v3/businesses/search'
     headers={'Authorization': 'Bearer %s' % secret.api_key}
     params={}
     params['location']='Chicago'
     params['price']=2
     results=model.make_request_using_cache(baseurl,headers,params)
     model.insert_table_from_api(results,'bars')
     conn = sqlite3.connect('final507.sqlite')
     cur = conn.cursor()
     statement='select r.lati,r.logi,r.name,r.id from restaurants_info as r join city_info as c on c.Id=r.city where r.price=? and c.name =? limit 20'
     cur.execute(statement,('$$', 'Chicago'))
     result=cur.fetchall()
     data,style=model.plot_prepare(result)
     self.assertIsInstance(data,list)
     self.assertIsInstance(style,dict)