Python library for the foursquare API
I have just released some open source code over at GitHub, it’s a simple wrapper library for the foursquare API. You should be familiar with the official API docs before making use of the library, since most of the parameters required are the same as the parameters for the foursquare API.
The full source code is available over at: http://github.com/zyelabs/python-foursquare
Grabbing the code:
- Download a zip file
- Download a tar file
- git clone git://github.com/zyelabs/python-foursquare.git
Installing
python setup.py install
Usage
import foursquare
#get help
help(foursquare)
# Instantiate a foursquare API class
api = foursquare.Api()
# Test if an API Request will work, returns True or False
test = api.test()
# Return a list of cities
cities = api.get_cities()
# Get the closest city for a given geolat & geolong
closest_city = api.check_city(-25.091874,27.057225)
# get checkins
checkins = api.get_checkins(username, password)
# get friends
friends = api.get_friends(username, password)
All the methods for the foursquare API have been implemented, just use pythons help system to get the different calls and methods. i.e run: help(foursquare)
Also note, with regards to optional params sent to the foursquare API the keyword argument name is mapped to that of the foursquare API. for example the userdetail endpoint takes an optional param mayor=1 the method in the library takes the same argument.
The only exception to this is the set_pings method, since the param required by foursquare is ‘self‘ . To use this method:
# set pings off (Globally) for authenticated user
api.set_pings(username, password, me='off')
# set pings on (globally)
api.set_pings(username, password, me='on')
# set pings on/off for a list of friends
# friends must be a list of dictionaries
# 1 to enable and 0 to disable
change_pings = [{'uid'=123, 'ping': 1}, {'uid'=456, 'ping': 0}]
api.set_pings(username, password, friends=change_pings, me='goodnight')
If you pick up any bugs or issues, pop me a message.
Tagged as api, code, foursquare, python + Categorized as Uncategorized
Hey,
(alright, this is my second try, this time I am going to save before trying to post).
I started playing with your little wrapper and it’s really nice.
One thing tho :
Let’s take get_cities() for example. I cant just do :
for city in api.get_cities():
print city["name"]
Because get_cities doesn’t return a list of cities, but a dictionary with one key “cities” whose value is the list of cities. So, the way the things are right now, I must do :
c = api.get_cities()
for city in c["cities"]:
print city["name"]
And I find it a little awkward…
Is there a particular reason why you have done things this way or we could hope for a version where get_cities (or any other method that is supposed to return a list) will actually return a list ?
Cheers.