Login

Tag "utility"

Snippet List

Quick script to convert json data to csv

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.

  • json
  • csv
  • utility
Read More

Shortcuts to your code organized by type (views, models, admin, ...)

Sometimes, when you're working on improving one specific aspect of your site, it's easier to browse your code by type than by application. E.g. you want quick access to all admin.py files because you're improving or customizing your admin site across the board and not for a specific app. This little management command adds a shortcuts dir to your project root that contains a bunch of symlinks to your code, organized in subdirs by type of code. You'll have to put this in `/management/commands/make_shortcuts.py` under an app of your choice. Usage: `python manage.py make_shortcuts`. Don't forget to ignore the /shortcuts directory in your source code management software.

  • shortcut
  • utility
  • organization
Read More

SQLite database vacuum script

This script can be run periodically (e.g. as a nightly cronjob) to keep a SQLite database with high churn from growing unnecessarily large.

  • db
  • utility
  • sqlite
Read More
Author: pbx
  • 4
  • 8

The chunkmaker

This is a general-purpose utility function, but since it uses lazy sequences via itertools, so it should be suitable for use with Querysets.

  • python
  • utility
  • sequence
  • itertools
Read More
Author: pbx
  • 4
  • 3

Import mail into a Django model

A mildly crufty script to slurp mail from an mbox into a Django model. I use a variant of this script to pull the contents of my scammy-spam mbox into the database displayed at <http://purportal.com/spam/>

  • email
  • faceless
  • utility
Read More
Author: pbx
  • 4
  • 11

6 snippets posted so far.