Joseph Votto
Joseph Votto

Reputation: 21

No results from API call in python

My API call in Python returns no results. It exits with code 0 but there is nothing displayed. Is there something I am missing? I am still new to Python and got the code from a YouTube tutorial. I am using my own API Key. Here is the code:

#!/usr/bin/env python
#Learn how this works here: http://youtu.be/pxofwuWTs7c

import urllib.request
import json

locu_api = 'XXXXXXXXXXXX'

def locu_search(query):
    api_key = locu_api
    url = 'https://api.locu.com/v1_0/venue/search/?api_key=' + api_key
    locality = query.replace(' ', '%20')
    final_url = url + "&locality=" + locality + "&category=restaurant"
    json_obj = urllib2.urlopen(final_url)
    data = json.load(json_obj)
    for item in data['objects']:
        print (item['name'], item['phone'])

Upvotes: 1

Views: 154

Answers (2)

Stefan Friedrich
Stefan Friedrich

Reputation: 188

You need to call your function first

locu_search('.....')

If there is no explicite exti(int) -> exit(0) is assumed.

Upvotes: 0

OJFord
OJFord

Reputation: 11140

Your script defines the function locu_search, but you are not calling it; thus the script terminates successfully - having successfully done nothing of any value.

You need to call your function after it is defined, like:

def locu_search(query):
    #snip

locu_search('San Francisco')

Upvotes: 1

Related Questions