Skip to content

Instantly share code, notes, and snippets.

@hmason
Last active July 29, 2023 19:21
Show Gist options
  • Save hmason/9005679 to your computer and use it in GitHub Desktop.
Save hmason/9005679 to your computer and use it in GitHub Desktop.
A quick script to fetch data from the locu api by query and zip code.
import sys
import os
import json
import csv
import time
import pickle
import requests
API_KEY = [YOUR API KEY GOES HERE]
class Locu(object):
def __init__(self):
pass
def menu_search(self, menu_item, postal_code):
params = {'api_key': API_KEY, 'postal_code': postal_code, 'name': menu_item }
url = "https://api.locu.com/v1_0/menu_item/search/?"
result = requests.get(url, params=params)
return json.loads(result.text)
if __name__ == '__main__':
l = Locu()
query = "cheeseburger" # add your term here
r = csv.reader(open('us_top_metro_zipcodes.csv', 'rU'))
for row in r:
zipcode = row[1]
print zipcode
m = l.menu_search(query, zipcode)
pickle.dump(m, open('data/' + zipcode + '.pickle','wb'))
time.sleep(.5)
Birmingham 35203
Huntsville 35813
Mobile 36601
Montgomery 36119
Anchorage 99599
Chandler 85225
Gilbert town 85296
Glendale 85302
Mesa 85201
Peoria 85381
Phoenix 85026
Scottsdale 85251
Tempe 85282
Tucson 85726
Little Rock 72202
Anaheim 92803
Antioch 94509
Bakersfield 93380
Berkeley 94704
Burbank 91505
Chula Vista 91910
Concord 94520
Corona 91718
Costa Mesa 92628
Daly City 94015
Downey 90241
El Monte 91734
Elk Grove 95624
Escondido 92025
Fairfield 94533
Fontana 92335
Fremont 94537
Fresno 93706
Fullerton 92834
Garden Grove 92842
Glendale 91205
Hayward 94544
Huntington Beach 92647
Inglewood 90301
Irvine 92619
Lancaster 93534
Long Beach 90802
Los Angeles 90052
Modesto 95350
Moreno Valley 92553
Norwalk 90650
Oakland 94612
Oceanside 92054
Ontario 91761
Orange 92863
Oxnard 93030
Palmdale 93550
Pasadena 91103
Pomona 91769
Rancho Cucamonga 91729
Richmond 94801
Riverside 92507
Roseville 95661
Sacramento 95813
Salinas 93907
San Bernardino 92401
San Buenaventura (Ventura) 93001
San Diego 92199
San Francisco 94188
San Jose 95101
Santa Ana 92711
Santa Clara 95050
Santa Clarita 91355
Santa Rosa 95402
Simi Valley 93065
Stockton 95208
Sunnyvale 94086
Thousand Oaks 91362
Torrance 90503
Vallejo 94590
Visalia 93277
West Covina 91793
Arvada 80004
Aurora 80017
Colorado Springs 80903
Denver 80202
Fort Collins 80525
Lakewood 80202
Pueblo 81003
Thornton 80221
Westminster 80030
Bridgeport 06602
Hartford 06101
New Haven 06511
Stamford 06904
Waterbury 06702
Washington1 20090
Cape Coral 33909
Clearwater 33990
Coral Springs 33075
Fort Lauderdale 33310
Gainesville 32601
Hialeah 33010
Hollywood 33022
Jacksonville 32203
Miami 33152
Miramar 33023
Orlando 32802
Pembroke Pines 33024
Pompano Beach 33060
Port St. Lucie 34952
St. Petersburg 33730
Tallahassee 32301
Tampa 33630
Athens-Clarke County2 30608
Atlanta 30304
Augusta-Richmond County3 30901
Columbus 31908
Savannah 31402
Honolulu CDP4 96820
Boise City 83708
Aurora 60505
Chicago 60607
Joliet 60436
Naperville 60540
Peoria 61601
Rockford 61125
Springfield 62703
Evansville 47708
Fort Wayne 46802
Indianapolis 46206
South Bend 46624
Cedar Rapids 52401
Des Moines 50318
Kansas City 66106
Olathe 66051
Overland Park 66204
Topeka 66603
Wichita 67276
Lexington-Fayette 40511
Louisville-Jefferson County5 40231
Baton Rouge 70826
Lafayette 70509
New Orleans 70113
Shreveport 71102
Baltimore 21202
Boston 02205
Cambridge 02139
Lowell 01853
Springfield 01101
Worcester 01613
Ann Arbor 48104
Detroit 48233
Flint 48502
Grand Rapids 49501
Lansing 48924
Sterling Heights 48311
Warren 48090
Minneapolis 55401
St. Paul 55109
Jackson 39205
Independence 64052
Kansas City 64108
Springfield 65801
St. Louis 63155
Lincoln 68501
Omaha 68108
Henderson 89015
Las Vegas 89199
North Las Vegas 89030
Reno 89510
Manchester 03103
Elizabeth 07208
Jersey City 07302
Newark 07102
Paterson 07510
Albuquerque 87101
Buffalo 14240
New York 10199
Rochester 14692
Syracuse 13220
Yonkers 10701
Cary 27511
Charlotte 28228
Durham 27701
Fayetteville 28302
Greensboro 27420
Raleigh 27613
Winston-Salem 27102
Akron 44309
Cincinnati 45225
Cleveland 44101
Columbus 43216
Dayton 45401
Toledo 43601
Norman 73019
Oklahoma City 73125
Tulsa 74107
Eugene 97401
Portland 97208
Salem 97309
Allentown 18101
Erie 16515
Philadelphia 19104
Pittsburgh 15290
Providence 02904
Charleston 29401
Columbia 29201
Sioux Falls 57104
Chattanooga 37421
Clarksville 37043
Knoxville 37950
Memphis 38101
Nashville-Davidson6 37230
Abilene 79604
Amarillo 79120
Arlington 76004
Austin 78710
Beaumont 77707
Brownsville 78520
Carrollton 75006
Corpus Christi 78469
Dallas 75260
Denton 76201
El Paso 79910
Fort Worth 76161
Garland 75040
Grand Prairie 75051
Houston 77201
Irving 75061
Killeen 76541
Laredo 78041
Lubbock 79402
McAllen 78501
Mesquite 75149
Pasadena 77501
Plano 75074
San Antonio 78284
Waco 76702
Salt Lake City 84199
West Valley City 84199
Alexandria 22314
Amarillo 79120
Arlington 76004
Austin 78710
Beaumont 77707
Brownsville 78520
Carrollton 75006
Corpus Christi 78469
Dallas 75260
Denton 76201
El Paso 79910
Fort Worth 76161
Garland 75040
Grand Prairie 75051
Houston 77201
Irving 75061
Killeen 76541
Laredo 78041
Lubbock 79402
McAllen 78501
Mesquite 75149
Pasadena 77501
Plano 75074
San Antonio 78284
Waco 76702
Utah
Salt Lake City 84199
West Valley City 84199
Virginia
Alexandria 22314
Arlington CDP 23320
Chesapeake 23670
Hampton 23607
Newport News 23501
Norfolk 23707
Portsmouth 23702
Richmond 23232
Virginia Beach 23450
Washington
Bellevue 98009
Seattle 98108
Spokane 99201
Tacoma 98413
Vancouver 98668
Wisconsin
Green Bay 54303
Madison 53714
Milwaukee 53203
@mgs27
Copy link

mgs27 commented Mar 20, 2014

Hi Hillary, I really enjoyed your piece on SciFri. I'm new to programming, learning as I go, interested in spatial data mostly. Simple question, since it doesn't seem evident here; what version of Python was this written for? Trying my hand at some debugging, getting stuck on pickle. Thanks in advance.

@josephmisiti
Copy link

should work with any version python 2.6+

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment