-
Notifications
You must be signed in to change notification settings - Fork 0
/
api_yelp.py
39 lines (32 loc) · 962 Bytes
/
api_yelp.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import os
from yelp.client import Client
from yelp.oauth1_authenticator import Oauth1Authenticator
import pydash as _
def obtain(search_term, category):
consumer_key = os.getenv('YELP_CONSUMER_KEY')
consumer_secret = os.getenv('YELP_CONSUMER_SECRET')
token = os.getenv('YELP_TOKEN')
token_secret = os.getenv('YELP_TOKEN_SECRET')
oauth = Oauth1Authenticator(
consumer_key=consumer_key,
consumer_secret=consumer_secret,
token=token,
token_secret=token_secret
)
client = Client(oauth)
results = client.search(search_term)
if not results.businesses:
return None
return {
"metadata": {
"type": "yelp-information",
"term": search_term,
"category": category
},
"data": {
"name": results.businesses[0].name,
"description": results.businesses[0].location.cross_streets,
"ratings": results.businesses[0].rating,
"images": results.businesses[0].image_url
}
}