def getYelpData(phoneNums): """ This function takes in a list of phone numbers and looks them up in Yelp Fusion using yelpapi. It then returns 2 dictionaries of the business' information and three pertinent user reviews of the business. param: phoneNums = List of phone numbers return: phoneDict = Dictionary mapping a phone number to a list. list[0] = the business' rating list[1] = the business' review count list[2] = the business' url return: reviewDict = Dictionary mapping a phone number to a list of reviews (up to 3 reviews available, chosen by Yelp algorithm) list[0] = the review's rating list[1] = the review's text list[2] = the review's time of creation (IN PACIFIC TIME) """ yelp_api = YelpAPI(APIKEY) phoneDict = dict() reviewDict = dict() #lineNum = 1 for phoneNum in phoneNums: #print(lineNum) response = yelp_api.phone_search_query(phone=str(phoneNum)) #print(phoneNum) #pprint(response) #lineNum = lineNum + 1 # If the phone number is listed in Yelp, store rating, review_count, url in # array mapped to phone number. Then, use the business-id field from # response to store 3 reviews in a separate list. Return both at end. if response['total'] != 0: business = response['businesses'][0] phoneDict[phoneNum] = [ business['rating'], business['review_count'], business['url'] ] # Get reviews using company id and store in reviewDict companyID = str(business['id']) reviewResponse = yelp_api.reviews_query(id=companyID) reviewList = reviewResponse['reviews'] # Put a list of review information in reviewDict (mapped to phone number) for review in reviewList: reviewDict[phoneNum] = [ review['rating'], review['text'], review['time_created'] ] return phoneDict, reviewDict
def parseYelpData(places, heading="tel"): """ This function takes in a list of businesses and looks them up by phone number in Yelp Fusion using yelpapi. It adds data about Yelp average rating of the business, the number of Yelp reviews, and the company's Yelp link to the dictionary of the business. The function then returns the updated list of businesses. param: places list of businesses that have been scraped by the GoogleParser param: heading default to "tel", signifying the heading for the phone number data field of each business return: updated list of businesses, with these data fields added to each business: 'yelp_rating', 'yelp_review_count', 'yelp_url','is_listed_yelp','is_claimed_yelp' """ yelp_api = YelpAPI(APIKEY) for place in places: phoneNum = changeFormatTel(place[heading]) if phoneNum == "": place['yelp_rating'] = "" place['yelp_review_count'] = "" place['yelp_url'] = "" place['is_listed_yelp'] = "0" place['is_claimed_yelp'] = "0" continue response = yelp_api.phone_search_query(phone=str(phoneNum)) # If the phone number is listed in Yelp, add Yelp rating, review_count, and # yelpUrl to the dictionary of the business. if response['total'] != 0: business = response['businesses'][0] place['yelp_rating'] = strip(str(business['rating'])) place['yelp_review_count'] = strip(str(business['review_count'])) place['yelp_url'] = strip(str(business['url'])) companyID = strip(str(business['id'])) claimResponse = yelp_api.business_query(id=companyID) place['is_listed_yelp'] = "1" if claimResponse['is_claimed'] == True: place['is_claimed_yelp'] = "1" else: place['is_claimed_yelp'] = "0" else: place['yelp_rating'] = "" place['yelp_review_count'] = "" place['yelp_url'] = "" place['is_listed_yelp'] = "0" place['is_claimed_yelp'] = "0" # to avoid Yelp's error messages of too many queries per second time.sleep(1) return places
def api(): yelp_api = YelpAPI( "92b7FDwkewHE9-5Ii9ig1hrlYWRtuzGWzaCTSRialTUvjhx7IpvJvRI2KP2T71WiWxlc8eu4ASfYfdiQbPXAkKQvaQyIypoI9j9DXeqecgrgw78PM2CXiJe_JKrsW3Yx" ) # args="?" # search_results = yelp_api.search_query(args) #print("10") response = yelp_api.phone_search_query(phone='+17189966288') # # print(response) # print("\n\n\n\n\n\n") # print (response['businesses'][0]['name']) return render_template('api.html', business=response)
def _get_yelp_data_by_phone_nbr(api_key, yelp_phone_numbers, manifest_folder, manifest_filename): """ Query Yelp business data from list of phone numbers and write to disk """ yelp_api = YelpAPI(api_key=api_key) yelp_busines_data = [] manifest = [] for phone_number in yelp_phone_numbers: yelp_busines_data.append( yelp_api.phone_search_query(phone=phone_number)) manifest.append({'phone_number': phone_number, 'api_called': True}) time.sleep( 0.1) # Limit because of TOO_MANY_REQUESTS_PER_SECOND error message manifest_filepath = create_csv_filepath(manifest_folder, manifest_filename) pd.DataFrame(manifest).to_csv(manifest_filepath) return yelp_busines_data
def home(): # CLIMATE DATA API url1 = "http://climatedataapi.worldbank.org/climateweb/rest/v1/country/mavg/tas/2020/2039/BRA" request1 = urllib.request.urlopen(url1) response1 = request1.read() d1 = json.loads(response1)[0] print("---------------") print("CLIMATE RESPONSE") print(d1) # BORED API url2 = "http://www.boredapi.com/api/activity/" request2 = urllib.request.urlopen(url2) response2 = request2.read() d2 = json.loads(response2) print("---------------") print("BORED RESPONSE") print(d2) # YELP API yelp_api = YelpAPI( "VUAGZaRKOeQggrzZ66K2o3hOYtqzi9UuL47M-hQkS3Hi5nMvyLRi3YTgGRbZXwrCHGMoybysDwBuInTsdkILZmtANvtd-6AGVx5cpQhqsnq-7Ls0dBW_eDChmgHuW3Yx" ) response3 = yelp_api.phone_search_query(phone='+13474258511') print("---------------") print("YELP RESPONSE") print(response3) return render_template("web.html", scenario=d1['scenario'], model=d1['gcm'], monthVals=d1['monthVals'], start=d1['fromYear'], end=d1['toYear'], activity=d2['activity'], accessibility=d2['accessibility'], type=d2['type'], participants=d2['participants'], price=d2['price'], name=response3['businesses'][0]['name'], rating=response3['businesses'][0]['rating'], price_rate=response3['businesses'][0]['price'], phone=response3['businesses'][0]['phone'], img=response3['businesses'][0]['image_url'])
def getYelpData(phoneNums): """ param: phoneNums = Numpy array of phone numbers """ yelp_api = YelpAPI(APIKEY) phoneDict = dict() reviewDict = dict() #lineNum = 1 for phoneNum in phoneNums: #print(lineNum) response = yelp_api.phone_search_query(phone=str(phoneNum)) #print(phoneNum) #pprint(response) #lineNum = lineNum + 1 # If the phone number is listed in Yelp, store rating, review_count, url in # array mapped to phone number. Then, use the business-id field from # response to store 3 reviews in a separate list. Return both at end. if response['total'] != 0: business = response['businesses'][0] phoneDict[phoneNum] = [ business['rating'], business['review_count'], business['url'] ] # Get reviews using company id and store in reviewDict companyID = str(business['id']) reviewResponse = yelp_api.reviews_query(id=companyID) reviewList = reviewResponse['reviews'] # Put a list of review information in reviewDict (mapped to phone number) for review in reviewList: reviewDict[phoneNum] = [ review['rating'], review['text'], review['time_created'] ] return phoneDict, reviewDict
response = yelp_api.search_query(categories='bikerentals', longitude=-122.4392, latitude=37.7474, limit=5) pprint(response) print( '\n-------------------------------------------------------------------------\n' ) """ Example phone search query. Phone Search API: https://www.yelp.com/developers/documentation/v3/business_search_phone """ print('***** search for business by phone number *****\n{}\n'.format( "yelp_api.phone_search_query(phone='+13193375512')")) response = yelp_api.phone_search_query(phone='+13193375512') pprint(response) print( '\n-------------------------------------------------------------------------\n' ) """ Example business match query with the 'best' type. Business Match API: https://www.yelp.com/developers/documentation/v3/business_match """ print('***** search for business best match *****\n{}\n'.format( "yelp_api.business_match_query(name='Splash Cafe', city='Pismo Beach', state='CA')" )) response = yelp_api.business_match_query(name='Splash Cafe', city='Pismo Beach', state='CA')
sort_by='rating', limit=5) pprint(response) print( '\n-------------------------------------------------------------------------\n' ) """ Example phone search query. Phone Search API: https://www.yelp.com/developers/documentation/v3/business_search_phone """ print('***** search for business by phone number *****\n{}\n'.format( "yelp_api.phone_search_query(phone='args.phone')")) if args.phone: response = yelp_api.phone_search_query(phone=args.phone) pprint(response) print( '\n-------------------------------------------------------------------------\n' ) """ Example transaction search query. Transaction Search API: https://www.yelp.com/developers/documentation/v3/transactions_search """ print( "***** businesses in Dallas supporting delivery transactions *****\n{}\n". format( "yelp_api.transaction_search_query(transaction_type='delivery', location='dallas, tx')" )) if args.transaction and args.location:
""" print('***** 5 bike rentals in San Francisco *****\n{}\n'.format("yelp_api.search_query(categories='bikerentals', " "longitude=-122.4392, latitude=37.7474, limit=5)")) response = yelp_api.search_query(categories='bikerentals', longitude=-122.4392, latitude=37.7474, limit=5) pprint(response) print('\n-------------------------------------------------------------------------\n') """ Example phone search query. Phone Search API: https://www.yelp.com/developers/documentation/v3/business_search_phone """ print('***** search for business by phone number *****\n{}\n'.format("yelp_api.phone_search_query(" "phone='+13193375512')")) response = yelp_api.phone_search_query(phone='+13193375512') pprint(response) print('\n-------------------------------------------------------------------------\n') """ Example business match query with the 'best' type. Business Match API: https://www.yelp.com/developers/documentation/v3/business_match """ print('***** search for business best match *****\n{}\n'.format("yelp_api.business_match_query(name='Splash Cafe', " "address1='197 Pomeroy Ave', ", "city='Pismo Beach', state='CA', country='US')")) response = yelp_api.business_match_query(name='Splash Cafe', address1='197 Pomeroy Ave', city='Pismo Beach',