newer posts | older posts

New year's Python meme

pythonFollowing in Tyrek Ziade's footsteps:

1. What’s the coolest Python application, framework or library you have discovered in 2009 ?

I hate to be so unoriginal... Django. I had been mostly using Zope 2/3 and Grok for web development (the latter is actually pretty cool).  But starting to work for PBS I got my first taste of Django and I was able to really completely dive in. Incredibly happy with it, I really appreciate all of the core functionality as well as a lot of contrib (not so much comments though, seriously what happened there?) and I feel like I can just get up and running much more quickly than before with minimal aggravation.

Just because Django is such a boring answer, I'll mention a few other really cool Python libs:

read more...
0 comments

An easy way to forward your django feed to feedburner

feedburner trafficIf you are using Django's syndication framework and want an easy way to track subscribers, Feedburner is probably your best bet. Of course if you already have a substantial amount of subscribers you'll want to forward the old feed to the new feed so as not to lose them.

I did this last week for this site and it worked very well, so if anyone else is trying to accomplish the same thing here is how I went about it:

First, I added the feedburner URL in settings.py (replace the URL with your own):

FEEDBURNER = 'http://feeds.feedburner.com/teebescom/'
read more...
1 comment

Playing with Google's Closure JS library

google closure tools image

On Thursday, Google open-sourced several of its JavaScript building blocks: a compiler, a library and template extension. They've been released together as the Closure toolkit.

I was particularly interested in its JavaScript library, specifically the graphics engine that implements the W3C's Scalable Vector Graphics as well as the event listeners. So I threw together a very small interactive app to play with the parts I'm curious about:

read more...
11 comments

A power companion for your smartphone

Often find yourself on the run with your phone or your iPod running low and no time to stop and recharge? 

I just picked up (at Harris Teeter, of all places) this pretty awesome gizmo I had read about a few weeks ago on one of the gadget blogs and that pretty much solves exactly that problem: the Duracell Instant Usb Charger.

  • Costs $35 (that's what I paid at the store and what Amazon sells it at, but I remember reading it can be gotten for as low as $20... Either way, it's cheap).
  • Gave my iPhone 60% power back in just over an hour and a half.
  • Uses USB both to charge other devices and itself be recharged.
  • Starts giving power as soon as you plug it

Overall a very thoughtfully designed little device that is cheap, slick, and useful to boot.

0 comments

Simple Python Twitter rss feed parser

If you want to display your tweets somewhere on your own web page, the easiest way is to use the RSS feed in your Twitter profile page (for example http://twitter.com/teebesz). Of course if you want to parse the @, # and links, you need just a little bit of code.

Here is the Python script I use for this site's Twitter display. You'll need the feedparser library installed (how have you been living without it anyway!)

import datetime
import feedparser
import re
    
def get_twitter(url, limit=3):
    """Takes a twitter rss feed and returns a list of dictionaries, one per
    tweet. Each dictionary contains two attributes:
        - An html ready string with the @, # and links parsed to the correct
        html code
        - A datetime object of the posted date"""

    twitter_entries = []
    for entry in feedparser.parse(url)['entries'][:limit]:

        # convert the given time format to datetime
        posted_datetime = datetime.datetime(
            entry['updated_parsed'][0],
            entry['updated_parsed'][1],
            entry['updated_parsed'][2],
            entry['updated_parsed'][3],
            entry['updated_parsed'][4],
            entry['updated_parsed'][5],
            entry['updated_parsed'][6],
        )
        
        # format the date a bit
        if posted_datetime.year == datetime.datetime.now().year:
            posted = posted_datetime.strftime("%b %d")
        else:
            posted = posted_datetime.strftime("%b %d %y")
        
        # strip the "<username>: " that preceeds all twitter feed entries
        text = re.sub(r'^\w+:\s', '', entry['title'])
        
# parse links
        text = re.sub(
            r"[^\"](http://(\w|\.|/|\?|=|%|&)+)",
            lambda x: "<a href='%s'>%s</a>" % (x.group(), x.group()),
            text)
        
        # parse @tweeter
        text = re.sub(
            r'@(\w+)',
            lambda x: "<a href='http://twitter.com/%s'>%s</a>"\
                 % (x.group()[1:], x.group()),
            text)
        
        # parse #hashtag
        text = re.sub(
            r'#(\w+)',
            lambda x: "<a href='http://twitter.com/search?q=%%23%s'>%s</a>"\
                 % (x.group()[1:], x.group()),
            text)
        
        twitter_entries.append({
            'text': text,
            'posted': posted,
            })
        
    return twitter_entries
4 comments