Skip to content

Instantly share code, notes, and snippets.

@codiez
codiez / 1-models.py
Created November 12, 2009 20:44
Django - Generic Custom Model Manager for summarizing data by any field
'''
This Snippet, lets you create a generic custom model manager to summarize data on a table by any field.
Benefits:
- You wont be repeating yourself!
- A single url & template can be used to summarize by any field in your model
Example Usage: Book.counts.by(field, year, month, day) i.e Book.counts.by(category, 2009, 9, 24)
Notes:
@codiez
codiez / django-get-options.py
Created November 12, 2009 21:23
Useful Django templatetag that passes a list of choices from your models.py as a context variable to your templates
'''
This Snippet creates a custom template tag for passing a context variable to your template with a list of choices from your models.py i.e
COL_CHOICES =(
(1, 'Not Applicable'),
(2, 'Black'),
)
Usage:
1. Save to template tags dir
'''
Runs a RAW SQL query in DJANGO and returns dictionaries to the template rather then a tuple
'''
from myapp.files.models import summary
from django.shortcuts import render_to_response
def generate_dicts(cur):
import itertools
fieldnames = [d[0].lower() for d in cur.description]
while True:
'''
This script grabs the currently playing song from Itunes and generates a dict with the song details such as name, artist, album, genre etc.
You need the appscript library
'''
from appscript import *
it = app('iTunes')
tags = ['name', 'artist','album','genre','played_date','duration']
if it.isrunning():
state = it.player_state.get()
@codiez
codiez / itunes_to_tweet.py
Created December 18, 2009 19:48
Post the currently playing song automatically to twitter, use as part of a service automator workflow
'''
Automatically post the currently playing track to twitter
Create an Automator service workflow to use
'''
import sys
from appscript import *
from os import popen
username=''
password=''
@codiez
codiez / itunes_notifications.py
Created December 20, 2009 20:14
Listen for distributed notifications from iTunes of the current song
'''
This python script listens for distributed notifications from iTunes of new songs playing,
works alot better then constantly polling.
'''
import Foundation
from AppKit import *
from PyObjCTools import AppHelper
class GetSongs(NSObject):
def getMySongs_(self, song):
@codiez
codiez / auto_send_note_iphone.py
Created December 22, 2009 13:22
Auto sends highlighted text to your iphone from any application, use in a service workflow
'''
To be used as part of an automator script, install as a service.
Sends the highlighted text to your iphone using prowl
'''
import sys
from prowl import Prowl
import Growl
notifier = Growl.GrowlNotifier('Prowl', ['status'])
#/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Prowlpy V0.4.2
Written by Jacob Burch, 7/6/2009
Python module for posting to the iPhone Push Notification service Prowl: http://prowl.weks.net/
"""
__author__ = '[email protected]'
"""
A Python module that enables posting notifications to the Growl daemon.
See <http://growl.info/> for more information.
"""
__version__ = "0.7"
__author__ = "Mark Rowe <[email protected]>"
__copyright__ = "(C) 2003 Mark Rowe <[email protected]>. Released under the BSD license."
__contributors__ = ["Ingmar J Stein (Growl Team)",
"Rui Carmo (http://the.taoofmac.com)",
"Jeremy Rossi <[email protected]>",