In [1]:
%pylab inline
from locu.api import VenueApiClient, MenuItemApiClient
import json


Populating the interactive namespace from numpy and matplotlib

In [2]:
venue_client = VenueApiClient('10848363d2e5411a0e845e017ce6ca51bf0b5ce2')

In [84]:
#zipcodes = ['94108','94133','94121','94118','94122','94109']
#zipcodes = ['94607','94014','94403']
#zipcodes = ['95125','95112','94704']
#zipcodes = ['94110','94131','94709']

In [85]:
venue_list = []
for zip in zipcodes:
    venues = venue_client.search(cuisine=['chinese'], postal_code=zip,category=['restaurant'],
                             has_menu=True)
    venue_list.append(venues)

In [86]:
venue_list


Out[86]:
[{u'meta': {u'cache-expiry': 3600, u'limit': 25},
  u'objects': [{u'categories': [u'other', u'restaurant'],
    u'country': u'United States',
    u'cuisines': [u'steakhouse / grill', u'chinese'],
    u'has_menu': True,
    u'id': u'40b4a7f02e9f10a20d6c',
    u'lat': 37.751532,
    u'locality': u'San Francisco',
    u'long': -122.41823,
    u'name': u'Dak Win Restaurant',
    u'phone': u'(415) 285-4455',
    u'postal_code': u'94110',
    u'region': u'CA',
    u'resource_uri': u'/v1_0/venue/40b4a7f02e9f10a20d6c/',
    u'street_address': u'2845 Mission St.',
    u'website_url': u'http://www.dwchinesefood.com/'},
   {u'categories': [u'other', u'restaurant'],
    u'country': u'United States',
    u'cuisines': [u'coffee / tea', u'chinese'],
    u'has_menu': True,
    u'id': u'a35b8f2958f3f54b3343',
    u'lat': 37.744707,
    u'locality': u'San Francisco',
    u'long': -122.420292,
    u'name': u'Jasmine Tea House',
    u'phone': u'(415) 826-6288',
    u'postal_code': u'94110',
    u'region': u'CA',
    u'resource_uri': u'/v1_0/venue/a35b8f2958f3f54b3343/',
    u'street_address': u'3253 Mission St.',
    u'website_url': u'http://www.jasmineteahouse.com/'},
   {u'categories': [u'other', u'restaurant'],
    u'country': u'United States',
    u'cuisines': [u'japanese', u'chinese'],
    u'has_menu': True,
    u'id': u'1f191157b9f458b94d1d',
    u'lat': 37.741535,
    u'locality': u'San Francisco',
    u'long': -122.422661,
    u'name': u'Shiso Chinese & Japanese Cuisine',
    u'phone': u'(415) 642-1987',
    u'postal_code': u'94110',
    u'region': u'CA',
    u'resource_uri': u'/v1_0/venue/1f191157b9f458b94d1d/',
    u'street_address': u'3452 Mission St.',
    u'website_url': u'http://www.shisorestaurantsf.com/'},
   {u'categories': [u'other', u'restaurant'],
    u'country': u'United States',
    u'cuisines': [u'steakhouse / grill', u'chinese'],
    u'has_menu': True,
    u'id': u'694c4e57cb6126f449f9',
    u'lat': 37.739061,
    u'locality': u'San Francisco',
    u'long': -122.416285,
    u'name': u'Hunan Chef',
    u'phone': u'(415) 648-3636',
    u'postal_code': u'94110',
    u'region': u'CA',
    u'resource_uri': u'/v1_0/venue/694c4e57cb6126f449f9/',
    u'street_address': u'519 Cortland Ave.',
    u'website_url': u'http://www.hunanchefsf.com'},
   {u'categories': [u'other', u'restaurant'],
    u'country': u'United States',
    u'cuisines': [u'chinese'],
    u'has_menu': True,
    u'id': u'3723b87870ce3846f4b0',
    u'lat': 37.753045,
    u'locality': u'San Francisco',
    u'long': -122.406534,
    u'name': u'Wok & Go',
    u'phone': u'(415) 642-4313',
    u'postal_code': u'94110',
    u'region': u'CA',
    u'resource_uri': u'/v1_0/venue/3723b87870ce3846f4b0/',
    u'street_address': u'2700 24th St.',
    u'website_url': u'http://www.wokandgosf.com/'},
   {u'categories': [u'other', u'restaurant'],
    u'country': u'United States',
    u'cuisines': [u'seafood', u'vegetarian', u'chinese'],
    u'has_menu': True,
    u'id': u'46f25e61621ff4a37090',
    u'lat': 37.743805,
    u'locality': u'San Francisco',
    u'long': -122.420888,
    u'name': u'Nulite Kitchen',
    u'phone': u'(415) 648-7724',
    u'postal_code': u'94110',
    u'region': u'CA',
    u'resource_uri': u'/v1_0/venue/46f25e61621ff4a37090/',
    u'street_address': u'3319 Mission St.',
    u'website_url': u'http://www.nulitekitchen.com'},
   {u'categories': [u'restaurant'],
    u'country': u'United States',
    u'cuisines': [u'american', u'chinese'],
    u'has_menu': True,
    u'id': u'7ff162aa66d7165a73d4',
    u'lat': 37.761274,
    u'locality': u'San Francisco',
    u'long': -122.419392,
    u'name': u'Lung Shan Restaurant',
    u'phone': u'(415) 863-2800',
    u'postal_code': u'94110',
    u'region': u'CA',
    u'resource_uri': u'/v1_0/venue/7ff162aa66d7165a73d4/',
    u'street_address': u'2234 Mission St.',
    u'website_url': u'http://www.missionchinesefood.com/'}]},
 {u'meta': {u'cache-expiry': 3600, u'limit': 25},
  u'objects': [{u'categories': [u'other', u'restaurant'],
    u'country': u'United States',
    u'cuisines': [u'fusion', u'asian', u'chinese'],
    u'has_menu': True,
    u'id': u'd05ffe3e6aeb8107022e',
    u'lat': 37.743695,
    u'locality': u'San Francisco',
    u'long': -122.428774,
    u'name': u"Alice's Restaurant",
    u'phone': u'(415) 282-8999',
    u'postal_code': u'94131',
    u'region': u'CA',
    u'resource_uri': u'/v1_0/venue/d05ffe3e6aeb8107022e/',
    u'street_address': u'1599 Sanchez St.',
    u'website_url': u'http://www.alicesrestaurantsf.com/'},
   {u'categories': [u'other', u'restaurant'],
    u'country': u'United States',
    u'cuisines': [u'vegetarian', u'american', u'seafood', u'chinese'],
    u'has_menu': True,
    u'id': u'83a3c7fc3e65d02f3743',
    u'lat': 37.746917,
    u'locality': u'San Francisco',
    u'long': -122.427069,
    u'name': u"Eric's Restaurant",
    u'phone': u'(415) 282-0919',
    u'postal_code': u'94131',
    u'region': u'CA',
    u'resource_uri': u'/v1_0/venue/83a3c7fc3e65d02f3743/',
    u'street_address': u'1500 Church St.',
    u'website_url': u'http://erics.ypguides.net'}]},
 {u'meta': {u'cache-expiry': 3600, u'limit': 25}, u'objects': []}]

In [87]:
#restaurant_list = []
for item in venue_list:
    print len(item['objects'])
    restaurant_list += item['objects']


7
2
0

In [97]:
len(restaurant_list)


Out[97]:
111

In [89]:
Sac = venue_client.search(cuisine=['chinese'], locality='Sacramento',category=['restaurant'],
                             has_menu=True)

In [96]:
restaurant_list += Sac['objects']

In [98]:
json.dump(restaurant_list, open('restaurants.json','w'))

In [99]:
len(restaurant_list)


Out[99]:
111

In [128]:
ids = [item['id'] for item in restaurant_list]

In [130]:
venue_client.get_menus??

In [136]:
b['objects'][0]['menus'] == a


Out[136]:
True

In [151]:
yield??


Object `yield` not found.

In [159]:
id_lists = []
for i in range(0,111,5):
    id_lists.append(ids[i:i+5])

In [163]:
id_lists[-1]


Out[163]:
[u'6371719ca793050e7e43']

In [164]:
# import MongoDB modules
from pymongo import MongoClient
from bson.objectid import ObjectId

# connect to the hosted MongoDB instance
client = MongoClient('mongodb://localhost:27017/')

# connect to the wikipedia database: if it does not exist it will automatically create it -- one reason why mongoDB can be nice.
db = client.restaurants

In [170]:
for item in id_lists:
    print item


[u'0d6420ef9825fd2e00ff', u'8a3d7ab187fcd777744d', u'55ae26fcae5d9461db29', u'16f61964ffc0e0d3d0a2', u'1da3345bb77bd14b87d8']
[u'd09492062ce1ac6202ba', u'c3dcbc27f208377b6ca3', u'c3c6e822137449bc2001', u'8b66120521ccbe829cb0', u'bda841ac0d505ceed6ac']
[u'5565bd49f17d19dff724', u'ed82ce4a5df02542b385', u'7534e62e89111159cb24', u'fea8758f92dba7ccaea3', u'124fcdb1a44d94806792']
[u'a903f8a8142e5fa852a6', u'09c97cbbc97e94019e90', u'c13db71c3d85765c3939', u'b07ab7263a2d66292ab4', u'c394062eb57d0500e553']
[u'f9a86143f76a66921587', u'7a1459731455d08fbd26', u'f202d5a09b5a57d2b7be', u'e8ee996188af2b2918ab', u'77c99bb592973c5fad67']
[u'd135e55770710896eae0', u'ff3fecb08c778415b2be', u'caa7c50afa281634fadb', u'6a3a1188c26be9090140', u'779b15e8ec9d47f0210c']
[u'242524f4d28e18f8c420', u'2feb385a70f4bc717424', u'145198d666fd26508f07', u'e12ad8c612b7557effff', u'44f1a23c22301f79f465']
[u'c437f4ac9ce12e45fac4', u'bd1aeae29e5fe40531bd', u'2c76de53f429d1a6c965', u'3b05a7b12605ec163df3', u'a72a73c55bfcb1c91629']
[u'67d513db4fbbd7aa07c6', u'd99cb7a1cf74428b296f', u'409d02515130f787bc0f', u'5ac5b99e759aa3dcd96e', u'6e5ebbc0d7e67b1f4435']
[u'2c186634ec244e2d9e5f', u'95b918ccc423496a13ba', u'ab1168d3b964bbf251aa', u'786ce768346abcaaaca0', u'9e3e3607ec6af17b2762']
[u'5414976f51b2f998ac14', u'05c4111e8fc2af51ca29', u'b52a1b8078a152f7ff73', u'fbc08dd530cd583406a3', u'2f8789710bff0982d35f']
[u'b2e35567c92f9d0a580a', u'03704c603f6a5f522bf6', u'12d03e6c422f5cece5e2', u'7e8184a18b9a5ca35996', u'f301dd4ee228d609b497']
[u'76320a5356d60362dbb9', u'b8922c20132839a903ad', u'cf7cfad114a5283dfc9c', u'1c8b3b3ae7e4a3a41120', u'bdc445eb9b6a0ad19ae3']
[u'd9d8b2e048900986e07a', u'dd59b0fbeee9ba56255e', u'af3dacb50cda3a1775a6', u'1a419059733d37bbb3dd', u'd5ac30d6c6ac88b61c06']
[u'4a76c37eb7dcb36c57a9', u'd5eb4c6cced2f2211022', u'3bdf837818f9aae84483', u'5d683acaa953a8da04a5', u'c1f0591d88312b19800b']
[u'5edba998d60b8b841b8a', u'c252b7f7cbefe0762068', u'5550f15c91881677dbdc', u'5383e97d807be919cdd2', u'40b4a7f02e9f10a20d6c']
[u'a35b8f2958f3f54b3343', u'1f191157b9f458b94d1d', u'694c4e57cb6126f449f9', u'3723b87870ce3846f4b0', u'46f25e61621ff4a37090']
[u'7ff162aa66d7165a73d4', u'd05ffe3e6aeb8107022e', u'83a3c7fc3e65d02f3743', u'b991473784ba313678f4', u'51d81cfed3cf1d7ca32c']
[u'0e98b77c93c0c5a5d08b', u'2ec85646fb25c5bb1668', u'ac20d7e0c30eba3773d8', u'4d67d324ace870352173', u'936a04494bb175acf768']
[u'2ade2d3f702d7929c674', u'95d39520481af49cf261', u'f4f4c8def4abe6afe707', u'a45227fc05103f47652d', u'540661b86d887156e7df']
[u'3b2d39caa189210a58c3', u'ee5baacdb1c71f47b88d', u'89594d1aee82d225637a', u'44fac6d3c3309c5ce584', u'cf196349973ba0e01d11']
[u'cf02f30efd07a475e24f', u'2ee1548137f1a44d1f1a', u'b0e8b6e85ec1e889472d', u'caf2f98f89e740f5354e', u'4da1236319b24c183ab6']
[u'6371719ca793050e7e43']

In [169]:
venue_client.get_details??

In [ ]: