Skip to content

Instantly share code, notes, and snippets.

@xufan6
Created April 29, 2012 16:50
Show Gist options
  • Save xufan6/2551840 to your computer and use it in GitHub Desktop.
Save xufan6/2551840 to your computer and use it in GitHub Desktop.
4sq categories
#/usr/bin/env python
# -*- coding: utf-8 -*-
import sys,urllib2,codecs
try: import simplejson as json
except ImportError: import json
CLIENT_ID="IYLVVWKAC110IENAZ53BJJUJEIDOSK5SVKKLDPAVLCHRLO45"
CLIENT_SECRET="KPW0QHUC2125TSWNZFLMHYXHHAN3BGXZRVZQYO5JS1RUZ3WS"
url="https://api.foursquare.com/v2/venues/categories?client_id="+CLIENT_ID+"&client_secret="+CLIENT_SECRET+"&v=20120615"
#url="file:///tmp/categories"
request = urllib2.urlopen(url, timeout=15).read()
if json.loads(request)["meta"]["code"] == 200:
response = json.loads(request)["response"]
else:
response = "error:"+response
sys.exit(1)
def wrapper_content(r,l):
"""give me a dict pls"""
if 'categories' in r and len(r['categories']) != 0:
l = l + 1
for a in r['categories']:
ico_link = a['icon']['prefix'] + "bg_32" + a['icon']['suffix']
li_html = u"%s* ![%s](%s) %s" % (" "*(l-1), a['name'], ico_link, a['name'])
print li_html.encode('utf-8')
wrapper_content(a,l)
print wrapper_content(response,0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment