Programming

Python FoursquareV2 library

0

At Fondu, location-based services, specifically foursquare, are incredibly important to us. Location with a social context is at the core of just about everything in our product.

 

When we originally migrated from PHP to Python, the offering of foursquare Python libraries was really lacking in terms of polish. So rather than bitch about it, we rolled our own. The goal was simple, Pythonic, and following the official API one-to-one. Full unit tests can't hurt either.

Naveen and the foursquare crew have been great to us as developers, so we'd like to give back by releasing our library. Check it out if you'd like a nicely-maintained foursquare Python library. As of this blog post I think it's the only up-to-date one that I could find.

 

The source is at https://github.com/mLewisLogic/foursquare

It's new, but it's already being used in a few projects, some in production. Let me know if there are improvements you'd like to see in it.

Asynchronous logging with MongoDB

0

One specific use case for MongoDB is as a user activity store. It's simple, scalable, and can be done asynchronously (as long as occasional failure is tolerable).

How? The gist is to keep your records in an array that you atomically push to.

MongoDB's documentation (http://www.mongodb.org/display/DOCS/Updating#Updating-%24push) should get you started on understanding how atomics work. Whenever you get a new event/activity that needs logging, just $push it to your array for storage or later processing. Make sure you set safe=False for whatever Mongo driver you're using. That will let it be done asynchronously, mostly eliminating the front-end cost of the operation.

Note: Mongo's $push operation can get pretty slow on really large lists, so take that into consideration.

How to install Python Imaging (PIL) in a virtualenv with –no-site-packages

2

This gets PIL working with JPEG/ZLIB support within a virtualenv (with –no-site-packages). This has specifically been tested with Python 2.7 on Ubuntu 11.04.

 

1. Install the dependencies needed for the PIL library, using aptitude. This installs everything but PIL itself.

sudo apt-get build-dep python-imaging

 

2. Install the python-dev package so that we can compile PIL.

sudo apt-get install python-dev

 

3. Make sure that PIL's setup.py can find JPEG/ZLIB, by supplying a settings override file. Ubuntu installs these libs in a non-standard place, so we need to let the package's installer know where to find them. Create a file named setup_site.py in the root of your virtualenv (or somewhere in your path) with the following contents:

JPEG_ROOT = ('/usr/lib/i386-linux-gnu/', '/usr/lib/x86_64-linux-gnu/')

ZLIB_ROOT = ('/usr/lib/i386-linux-gnu/', '/usr/lib/x86_64-linux-gnu/')

FREETYPE_ROOT = ('/usr/lib/i386-linux-gnu/', '/usr/lib/x86_64-linux-gnu/')

 

4. From the root of your virtualenv (with it activated) run:

pip install PIL

 

That's it! If you run into any problems on Ubuntu 11.04+, leave a comment and I'll try to update the post accordingly.

Go to Top