Snippet List
I often need to dump data from a database to csv. This little snippet should make it easy enough to do without having to worry too much about character encodings, though it does assume you want your csv file to be utf-8 encoded.
Note that this dumps just one table from the database. Trying to dump all the tables in your app will raise an exception.
This adds an 'fbshell' management command which starts up a Python shell with an authenticated [pyfacebook](http://code.google.com/p/pyfacebook/) instance ready to make requests.
This is very useful for testing out facebook requests or performing administration tasks without hooking a debugger into your application.
This snippet should be saved to
/yourproject/management/commands/fbshell.py
See [custom management commands](http://docs.djangoproject.com/en/dev/howto/custom-management-commands/) for a description of how this works.
If you are already using pyfacebook in your app then you'll already have the right settings, so just run :
$ python manage.py fbshell
A browser window will pop up, prompting you for authentication (unless you're already logged in to facebook). Press enter in the shell when you're finished this, and you'll be dropped into a shell with the session key, uuid, and name printed.
Now you can use the facebook instance:
>>> facebook.friends.get()
>>> [...]
If you haven't used pyfacebook in your app, you'll need at least the following settings in your settings.py
FACEBOOK_API_KEY = 'your_api_key'
FACEBOOK_SECRET_KEY = 'your_secret_key'
- management
- shell
- facebook
- command
stephenemslie has posted 2 snippets.