Ejemplo n.º 1
0
    def authorize(self):
        try:
            session_file = open(".grsession", "r")
            saved_session = session_file.readline()
            [access_token, access_token_secret] = saved_session.split(":")
            print("got session! (" + access_token + ", " +
                  access_token_secret + ")")
            self.session = rauth.OAuth1Session(self.consumer_key,
                                               self.consumer_secret,
                                               access_token,
                                               access_token_secret)
        except IOError as err:
            session_file = open(".grsession", "w")
            # have to open a new session
            request_token, request_token_secret = self.service.get_request_token(
                header_auth=True)
            authorize_url = self.service.get_authorize_url(request_token)

            print "Visit this URL in your browser " + authorize_url
            accepted = 'n'
            while accepted == 'n':
                print "Have you authorized me? (y/n) "
                accepted = raw_input()

            access_tok, access_tok_secret = self.service.get_access_token(
                request_token, request_token_secret)
            self.session = rauth.OAuth1Session(self.consumer_key,
                                               self.consumer_secret,
                                               access_tok, access_tok_secret)

            session_file.write(access_tok + ":" + access_tok_secret)
            session_file.close()
Ejemplo n.º 2
0
def get_business(city, state, category, num):
    """
    Given parameters return search results from Yelp API.
    """
    params = get_para(city, state, category, num)
    
    consumer_key = "FHjUV_8ZnrKQ-WX22Bb1cw"
    consumer_secret = "MSAajBT2EPztDh5I-t9PVAhxnO4"
    token = "X8ic1b2V0QVB25BqcXtL_XFI1mJo_Wy3"
    token_secret = "wTok52fM7BEYgDBDD0eqNflEiMo"

    session = rauth.OAuth1Session(
        consumer_key = consumer_key,
        consumer_secret = consumer_secret,
        access_token = token,
        access_token_secret = token_secret)
    request = session.get("http://api.yelp.com/v2/search",params=params)
    #Transforms the JSON API response into a Python dictionary
    businesses = request.json()
    session.close()
    #handle the situation where there are not enough restaurants given the requirements
    if 'businesses' not in list(businesses.keys()):
        #each category needs to have at least 6 restaurants
        if num <= 5:
            return None
        else:
            time.sleep(1.0)
            return get_business(city, state, category, num-5)
    return businesses['businesses']
Ejemplo n.º 3
0
def get_yelp_ratings(business_id):
    """ Returns yelp ratings and related yelp information for a food truck 
	with a given business id """

    # OAuth credentials
    CONSUMER_KEY = os.environ.get('YELP_CONSUMER_KEY')
    CONSUMER_SECRET = os.environ.get('YELP_CONSUMER_SECRET')
    TOKEN = os.environ.get('YELP_TOKEN')
    TOKEN_SECRET = os.environ.get('YELP_TOKEN_SECRET')

    session = rauth.OAuth1Session(consumer_key=CONSUMER_KEY,
                                  consumer_secret=CONSUMER_SECRET,
                                  access_token=TOKEN,
                                  access_token_secret=TOKEN_SECRET)

    url = "http://api.yelp.com/v2/business/{0}".format(business_id)
    print "**** url", url

    try:
        request = session.get(url)
        # transform json api response into dictionary
        data = request.json()
    except ValueError:
        return False

    session.close()

    return data
Ejemplo n.º 4
0
def get_results(params):
    """Code Credit: https://www.yelp.com/developers/documentation/v2/search_api"""
    consumer_key = "KovDTH7ny8SZK65BXJYevA"
    consumer_secret = "nl-LlP5LvsxjqNOEzGh3gAeJutQ"
    token = "qy63e6141tPLOu_EIlG7N1ezwbd14m5t"
    token_secret = "aYSIVN7tNDmsbYJpsEfoUGWTlhY"
   
    session = rauth.OAuth1Session(
    consumer_key = consumer_key
    ,consumer_secret = consumer_secret
    ,access_token = token
    ,access_token_secret = token_secret)
     
    request = session.get("http://api.yelp.com/v2/search",params=params)
   
    #Transforms the JSON API response into a Python dictionary
    if request.status_code==200:
        data = request.json()
        session.close()
        return(data)
    else:
        print("Status not OK, ", request.json())
        data = request.json()
        session.close()
        return(data)
Ejemplo n.º 5
0
def get_review(businessID):
    """
    Given a businessID (returned from get_business) return a dictionary containing
    information about the top review (review text, user id, user rating and time created).
    """
    consumer_key = "FHjUV_8ZnrKQ-WX22Bb1cw"
    consumer_secret = "MSAajBT2EPztDh5I-t9PVAhxnO4"
    token = "X8ic1b2V0QVB25BqcXtL_XFI1mJo_Wy3"
    token_secret = "wTok52fM7BEYgDBDD0eqNflEiMo"

    session = rauth.OAuth1Session(
        consumer_key = consumer_key,
        consumer_secret = consumer_secret,
        access_token = token,
        access_token_secret = token_secret)
    request = session.get("http://api.yelp.com/v2/business/"+businessID)
    data = request.json()
    session.close()
    #handle the situation where there are no reviews
    if 'reviews' not in list(data.keys()):
        return None
    data = data['reviews'][0]
    review = {}
    review['uid'] = data['user']['id']
    review['review'] = data['excerpt']
    review['urating'] = data['rating']
    review['time_created'] = data['time_created']
    return review
Ejemplo n.º 6
0
def get_results(params):

    # Obtain these from Yelp's manage access page
    # Pulls keys from keys python file
    consumer_key = keys.YELP_CONSUMER_KEY
    consumer_secret = keys.YELP_CONSUMER_SECRET
    token = keys.YELP_TOKEN
    token_secret = keys.YELP_TOKEN_SECRET

    # Obtain these from Yelp's manage access page
    consumer_key = keys.YELP_CONSUMER_KEY
    consumer_secret = keys.YELP_CONSUMER_SECRET
    token = keys.YELP_TOKEN
    token_secret = keys.YELP_TOKEN_SECRET

    session = rauth.OAuth1Session(consumer_key=consumer_key,
                                  consumer_secret=consumer_secret,
                                  access_token=token,
                                  access_token_secret=token_secret)

    request = session.get("http://api.yelp.com/v2/search", params=params)

    # Transforms the JSON API response into a Python dictionary
    data = request.json()
    session.close()
    return data
def get_results(params):

    #Obtain these from Yelp's manage access page
    consumer_key = 'PnHvincoddn76xfpm3LhLg'
    consumer_secret = 'PGmBEyjY0dKu1jzYkJr2Mxe2SCs'
    token = 'Xo8UWIL1CdyTxn-cX-XYbxsAXQOpgfYz'
    token_secret = '1J60nMB-wGTsLyNOyGkY9EZfMFM'

    #consumer_key = "YOUR_KEY"
    #consumer_secret = "YOUR_SECRET"
    #token = "YOUR_TOKEN"
    #token_secret = "YOUR_TOKEN_SECRET"

    session = rauth.OAuth1Session(consumer_key=consumer_key,
                                  consumer_secret=consumer_secret,
                                  access_token=token,
                                  access_token_secret=token_secret)

    request = session.get("http://api.yelp.com/v2/search", params=params)

    #Transforms the JSON API response into a Python dictionary
    data = request.json()
    session.close()

    return data
Ejemplo n.º 8
0
def get_results(params):

    #Obtain these from Yelp's manage access page
    consumer_key = "b6QDLmFXAPdYGpkhcJb_fA"
    consumer_secret = "egb22LOu9VO4g5ca0WXpkA-R8C4"
    token = "qcOKKAAJ3McnvRgPkt47LYS7nZs7tHpt"
    token_secret = "taMNb3tGNhuLCxnf7p0lfnmuf9A"

    session = rauth.OAuth1Session(consumer_key=consumer_key,
                                  consumer_secret=consumer_secret,
                                  access_token=token,
                                  access_token_secret=token_secret)

    request = session.get("http://api.yelp.com/v2/search", params=params)
    #print request.text
    #Transforms the JSON API response into a Python dictionary
    data = request.json()
    session.close()
    print data["region"]
    businesses_id = data["businesses"][0]["id"]
    #print data
    print len(data["businesses"])

    request = session.get("https://api.yelp.com/v2/business/" + businesses_id)

    print "\n\n\n\n\n\n\n\n"
    print request.text

    return data
Ejemplo n.º 9
0
async def odnowsesje():
    for ajdi in zapisane:
        if "ats" in zapisane[ajdi]:
            print("Probuje przywrocic sesje dla", ajdi)
            at = zapisane[ajdi]['at']
            ats = zapisane[ajdi]['ats']
            auth = rauth.OAuth1Session(consumer_key=client_key,
                                       consumer_secret=client_secret,
                                       access_token=at,
                                       access_token_secret=ats)
            sesje[ajdi] = auth
            sesja = sesje[ajdi]
            parametry = {"days": 365}
            response = sesja.get(base_url + "services/grades/latest",
                                 params=parametry)
            if len(response.json()) != 0:
                ile = 0
                for ocena in response.json():
                    ile = ile + 1
                if ajdi in ocenki:
                    if int(ocenki[ajdi]) < ile:
                        ocenki[ajdi] = ile
                        user = bot.get_user(int(ajdi))
                        await user.send(
                            "Hej " + user.name +
                            "! Na USOSie pojawiła się nowa ocena! Sprawdź wpisując !oceny"
                        )
                else:
                    ocenki[ajdi] = ile
            else:
                ocenki[ajdi] = 0
    with open("ocenki.json", "w", encoding='utf-8') as zapisz_ocenki:
        json.dump(ocenki, zapisz_ocenki, ensure_ascii=False, indent=4)
Ejemplo n.º 10
0
def get_results(marker):
  #print(marker)
  marker = marker.split(',')
  params = {}
  params["term"] = marker[0]
  params['location'] = marker[1]
  params['limit'] = 1

  #Obtain these from Yelp's manage access page
  consumer_key = "4b4fYhbrF1iACNoVhJgcUw"
  consumer_secret = "KisZwYHT3ajmwlJ1NQV2KQ2Na4A"
  token = "lMULtSEEwQ3ijnhHSDcqlzLeXod1xQ65"
  token_secret = "OPZ_UG0aYIWrv2Am6WfUBwf-ccg"
  
  session = rauth.OAuth1Session(
    consumer_key = consumer_key
    ,consumer_secret = consumer_secret
    ,access_token = token
    ,access_token_secret = token_secret)
  
  request = session.get("http://api.yelp.com/v2/search/?",params=params)
  
  #Transforms the JSON API response into a Python dictionary
  data = ""
  try:
    data = request.json()
  except:
    pass

  try:
    session.close()
  except:
    pass
  
  return json.dumps(data)
Ejemplo n.º 11
0
def search(lat, lng, distance):
    """
    Searches the Yelp API (Max Limit = 20)

    :param lat: Latitude of the request
    :param long: Longitude of the request
    :param distance: Distance to search (meters)
    :returns: List of retrieved businesses
    """

    params = {}
    params['term'] = 'nightlife,night_club,restaurant'
    params['ll'] = '{},{}'.format(lat, lng)
    params['radius_filter'] = distance

    session = rauth.OAuth1Session(consumer_key=CONSUMER_KEY,
                                  consumer_secret=CONSUMER_SECRET,
                                  access_token=TOKEN,
                                  access_token_secret=TOKEN_SECRET)

    request = session.get('https://api.yelp.com/v2/search', params=params)
    data = request.json()
    session.close()

    business_list = []
    for business in data['businesses']:
        business_list.append(
            Business(business['name'],
                     business['location']['display_address'][0],
                     business['rating'], business['review_count'], 'N/A'))
    return business_list
Ejemplo n.º 12
0
def yelp_search(lat, lng, category=None):
    if category is None:
        category = "restaurants"

    params = {
        #"term": "restaurant",
        "category_filter": category,
        "ll": "{},{}".format(lat, lng),
        "radius_filter": "1600",  #in meters
        "sort":
        "2",  # highest rated: https://www.yelp.com/developers/documentation/v2/search_api
    }

    session = rauth.OAuth1Session(
        consumer_key=secret_keys.YELP_CONSUMER_KEY,
        consumer_secret=secret_keys.YELP_CONSUMER_SECRET,
        access_token=secret_keys.YELP_TOKEN,
        access_token_secret=secret_keys.YELP_TOKEN_SECRET)

    request = session.get("http://api.yelp.com/v2/search", params=params)

    #Transforms the JSON API response into a Python dictionary
    data = request.json()

    session.close()
    return data
Ejemplo n.º 13
0
def get_results(params):
    session = rauth.OAuth1Session(consumer_key=yelp_api_keys[0],
                                  consumer_secret=yelp_api_keys[1],
                                  access_token=yelp_api_keys[2],
                                  access_token_secret=yelp_api_keys[3])
    request = session.get("http://api.yelp.com/v2/search/", params=params)
    #Transforms the JSON API response into a Python dictionary
    data = request.json()
    return data
Ejemplo n.º 14
0
def get_result(params, creds):
    session = rauth.OAuth1Session(consumer_key=creds['consumer_key'],
                                  consumer_secret=creds['consumer_secret'],
                                  access_token=creds['token'],
                                  access_token_secret=creds['token_secret'])

    request = session.get("http://api.yelp.com/v2/search", params=params)

    #Transforms the JSON API response into a Python dictionary
    data = request.json()
    return data
Ejemplo n.º 15
0
def get_results(params):
    ##Obtain these from Yelp's manage access page (adding this to test heroku)
    session = rauth.OAuth1Session(
        consumer_key=os.environ['yelp_consumer_key'],
        consumer_secret=os.environ['yelp_consumer_secret'],
        access_token=os.environ['yelp_token'],
        access_token_secret=os.environ['yelp_token_secret'])

    request = session.get("http://api.yelp.com/v2/search", params=params)

    #Transforms the JSON API response into a Python dictionary
    return request.json()
Ejemplo n.º 16
0
def get_results(params):
    session = rauth.OAuth1Session(consumer_key=consumer_key,
                                  consumer_secret=consumer_secret,
                                  access_token=token,
                                  access_token_secret=token_secret)

    request = session.get("http://api.yelp.com/v2/search", params=params)
    #Transforms the JSON API response into a Python dictionary
    data = request.json()
    session.close()

    return data
Ejemplo n.º 17
0
async def zaloguj(ctx):
    ajdi = str(ctx.message.author.id)
    global sesje
    global oauth
    global zapisane
    try:
        if ajdi in zapisane:
            print(ajdi, "wpisał !zaloguj, próbuję wznowić sesję.")
            at = zapisane[ajdi]['at']
            ats = zapisane[ajdi]['ats']
            auth = rauth.OAuth1Session(consumer_key=client_key,
                                       consumer_secret=client_secret,
                                       access_token=at,
                                       access_token_secret=ats)
            sesje[ajdi] = auth
            response = auth.get(base_url + "services/users/user")
            await ctx.send(f'Wznowiono poprzednia sesje logowania.')
            print("Udane")
        else:
            print("Tworzę nową sesje dla", ajdi)
            oauth = rauth.OAuth1Service(consumer_key=client_key,
                                        consumer_secret=client_secret,
                                        name="DiscordBot",
                                        request_token_url=request_token_url,
                                        authorize_url=authorize_url,
                                        access_token_url=access_token_url)
            params = {'oauth_callback': 'oob', 'scopes': SCOPES}
            tokeny = oauth.get_request_token(params=params)
            request_token, request_token_secret = tokeny
            zapisane[ajdi] = {'rt': request_token, 'rts': request_token_secret}
            url = oauth.get_authorize_url(request_token)
            await ctx.send("Wysłano link w prywatnej wiadomości.")
            await ctx.author.send(
                "Odwiedź poniższy link i odpisz mi: !pin twojpin")
            await ctx.author.send(url)
    except:
        print("Tworzę nową sesje dla", ajdi)
        oauth = rauth.OAuth1Service(consumer_key=client_key,
                                    consumer_secret=client_secret,
                                    name="DiscordBot",
                                    request_token_url=request_token_url,
                                    authorize_url=authorize_url,
                                    access_token_url=access_token_url)
        params = {'oauth_callback': 'oob', 'scopes': SCOPES}
        tokeny = oauth.get_request_token(params=params)
        request_token, request_token_secret = tokeny
        zapisane[ajdi] = {'rt': request_token, 'rts': request_token_secret}
        url = oauth.get_authorize_url(request_token)
        await ctx.send("Wysłano link w prywatnej wiadomości.")
        await ctx.author.send("Odwiedź poniższy link i odpisz mi: !pin twojpin"
                              )
        await ctx.author.send(url)
Ejemplo n.º 18
0
def authenticate():
    """Return session object required to request a search"""

    consumer_key = 'Jjw5GZkJ8rLbcrKmGW5RwA'
    consumer_secret = 'uVgw3EhnfLEABve48wA4UmkbJp4'
    token = 'B2nfmgjMT6a8d5XYck6bScczxW1gRxdt'
    token_secret = '_1n06oKU5smCTns1YWBPZjjit3E'

    session = rauth.OAuth1Session(consumer_key=consumer_key,
                                  consumer_secret=consumer_secret,
                                  access_token=token,
                                  access_token_secret=token_secret)
    return session
Ejemplo n.º 19
0
 def __init__(self, consumer_key, access_token, api_base = 'http://api.shapeways.com'):
     '''
     consumer_key is a (public, secret) tuple of your application's consumer key
     access_token is a (public, secret) tuple of the access key you got for your application to access a particular user's account
     '''
     self.session = rauth.OAuth1Session(
         consumer_key = consumer_key[0],
         consumer_secret = consumer_key[1],
         access_token = access_token[0],
         access_token_secret = access_token[1]
     )
     
     self.api_base = api_base
Ejemplo n.º 20
0
def queryAPI(params):

    session = rauth.OAuth1Session(
        consumer_key = config.key,
        consumer_secret = config.secret,
        access_token = config.token,
        access_token_secret = config.secret_token
    )

    request = session.get(API_BASE, params = params)
    data = request.json()
    session.close()

    return data
Ejemplo n.º 21
0
def yelp_search(params, secretsfile=secretsfile):
    #pulls secrets, searches api, returns response
    secrets = []
    with open(secretsfile, 'r') as sf:
        for line in sf:
            secrets.append(str(line.strip()))

    session = rauth.OAuth1Session(consumer_key=secrets[0],
                                  consumer_secret=secrets[1],
                                  access_token=secrets[2],
                                  access_token_secret=secrets[3])

    request = session.get("http://api.yelp.com/v2/search", params=params)
    data = request.json()
    session.close()
    return data
Ejemplo n.º 22
0
def get_results(params):

    #Obtain these from Yelp's manage access page
    consumer_key = "H2auu1fDvBFJdx_0C8OsoA"
    consumer_secret = "uUhBs9q4v0-HaWvNmsb2KgJ8GP0"
    token = "CJk_pXojjW8Wavvo5UhjXvdAg7SOhkHp"
    token_secret = "7SjI2AseFjzBBPnoSnOJf0dh1eE"

    session = rauth.OAuth1Session(consumer_key=consumer_key,
                                  consumer_secret=consumer_secret,
                                  access_token=token,
                                  access_token_secret=token_secret)

    request = session.get("http://api.yelp.com/v2/search", params=params)
    session.close()
    return request.text
Ejemplo n.º 23
0
def get_results(params):
    consumer_key = 'Yq7dBOlGfiZ5cDATqK4NiQ'
    consumer_secret = '4XyV0YEv326nAwH_USfn95EWZik'
    token = 'Xjz-nLqH0NR0GhSTMGZh_kYGN3mKGonI'
    token_secret = '2Ie0QCj0AGkvxiGsp3vNxZI_a24'

    session = rauth.OAuth1Session(consumer_key=consumer_key,
                                  consumer_secret=consumer_secret,
                                  access_token=token,
                                  access_token_secret=token_secret)
    request = session.get("http://api.yelp.com/v2/search", params=params)
    #Transforms the JSON API response into a Python dictionary
    data = request.json()
    session.close()

    return data
Ejemplo n.º 24
0
def get_results(params):
    consumer_key = "7RUTKX5es62WOntKA21eIQ"
    consumer_secret = "DQwFZ0jnvbvOyXW66YtDDzbIDaE"
    token = "fnplPbdXdEqfGQUWIVNErZoZvd6cIAZX"
    token_secret = "5CZ7HEqx7O3xbSeqducRpwKDTIE"

    session = rauth.OAuth1Session(consumer_key=consumer_key,
                                  consumer_secret=consumer_secret,
                                  access_token=token,
                                  access_token_secret=token_secret)

    request = session.get("http://api.yelp.com/v2/search", params=params)
    data = request.json()
    session.close()

    return data
Ejemplo n.º 25
0
    def request_yelp_search(self, request_parameters):
        session = rauth.OAuth1Session(
            consumer_key=self.consumer_key,
            consumer_secret=self.consumer_secret,
            access_token=self.token,
            access_token_secret=self.token_secret)

        request = session.get(
            'http://api.yelp.com/v2/search',
            params=request_parameters)

        print request.url

        data = request.json()
        session.close()

        return data
Ejemplo n.º 26
0
def get_restaurants(params):
    consumer_key = inifile.get("yelp", "consumer_key")
    consumer_secret = inifile.get("yelp", "consumer_secret")
    access_token = inifile.get("yelp", "access_token")
    access_token_secret = inifile.get("yelp", "access_token_secret")

    session = rauth.OAuth1Session(consumer_key=consumer_key,
                                  consumer_secret=consumer_secret,
                                  access_token=access_token,
                                  access_token_secret=access_token_secret)

    request = session.get("http://api.yelp.com/v2/search", params=params)

    data = request.json()
    session.close()

    return data
Ejemplo n.º 27
0
def getData(params):
    # setting up personal Yelp account
    with open("config_secret.json",'r') as json_file:
        json_data = json.load(json_file)
          
    session = rauth.OAuth1Session(
        consumer_key = json_data["consumer_key"],
        consumer_secret = json_data["consumer_secret"],
        access_token = json_data["token"],
        access_token_secret = json_data["token_secret"])

    request = session.get("http://api.yelp.com/v2/search", params=params)
    
    #transforming the data in JSON format
    data = request.json()
    session.close()
    return data
Ejemplo n.º 28
0
def get_results(params):
	consumer_key = "TwiZjmvAvrct4Xu6OxN49w"
	consumer_secret = "Ul7lj0H4wBdvPdY8Ci9eZkdI4tE"
	token = "B93gZUtPLgD5KRc-IwBicN3qt30xUt2B"
	token_secret = "p_gv7ofsb_LAfl-_u8hL30ezLrY"

	session = rauth.OAuth1Session(
		consumer_key = consumer_key
		,consumer_secret = consumer_secret
		,access_token = token
		,access_token_secret = token_secret)

	request = session.get("http://api.yelp.com/v2/search", params = params)

	data = request.json()
	session.close()

	return data
Ejemplo n.º 29
0
def get_results(params):
    # Obtain these from Yelp's manage access page
    consumer_key = 'uOZv9SZSepVUp2s29CyWmA'
    consumer_secret = 'akcl2MJFNuJE9lfNlG4fI3Y_Oj8'
    token = 'kqFnFl_rs7IFhQEyxBZTzq0XZbOqea65'
    token_secret = '-z5NBbAGcO4Do_cYZfrbkR5oik4'

    session = rauth.OAuth1Session(consumer_key=consumer_key,
                                  consumer_secret=consumer_secret,
                                  access_token=token,
                                  access_token_secret=token_secret)

    request = session.get("http://api.yelp.com/v2/search", params=params)

    # Transforms the JSON API response into a Python dictionary
    data = request.json()
    session.close()

    return data
Ejemplo n.º 30
0
def get_results(params):

    #Obtain these from Yelp's manage access page
    configini = configparser.ConfigParser()
    configini.read('app/secrets/config.ini')

    session = rauth.OAuth1Session(
        consumer_key=configini['YELP']['consumer_key'],
        consumer_secret=configini['YELP']['consumer_secret'],
        access_token=configini['YELP']['token'],
        access_token_secret=configini['YELP']['token_secret'])

    request = session.get("http://api.yelp.com/v2/search", params=params)

    #Transforms the JSON API response into a Pandas dataframe
    data = cleanData(request.json())
    session.close()

    return data