Posts Tagged ‘python’

Search and Replace With Python

Monday, May 19th, 2008

Today I had a large (re: 4GB) file that I needed to do some search and replace on, and none of my text editors including my beloved Textmate could even open the file. So I turned to the most trusty of tools in my tool chest which is python!

f = open(infile, “r”)
n = open(outfile, “w”)
for line in f:
output = line.replace(oldtext, newtext)
n.write(output)

In just a couple of minutes I had a new file with the changes I needed. Its pretty basic stuff, but non-programmers (especially those that don’t use languages like python) might not think of trying.

pyFlickrFan

Tuesday, February 26th, 2008

On twitter ages ago I wrote pyFlickrFan.  I thought I might have turned it into an app like what we did with pyPodder into iPodderX. August and I were even talking about it on and off.  Then the last keynote happened and it sounded like Apple was building all the functionality into Apple TV.  So the project sat dormant on my machine running every once in a while.

So I decided now to release the code incase anyone else wanted to check it out.

pyflickrfan

And here is the source

ps: Thanks to Dave Winer who came up with the concept and original FlickrFan app

Special:Feeds

Friday, February 1st, 2008

Today I posted a message in the Google Group for Mahalo Development that talked about a new set of tools for 3rd party developers.

Along with Mahalo Social we deployed a new Special page to handle feeds for that data. We are providing them in Atom, RSS2 and JSON formats (we just added JSON a couple of days ago)
I wrote up a quick example for reading in your links that you have submitted to Mahalo via Python using the JSON output format
import simplejson, urllib2
f = urllib2.urlopen('http://www.mahalo.com/Special:Feeds?group=people
                            &un=rslakinski&action=links&type=json');
data = f.read()
links = simplejson.loads(data)
del(data)
if len(links) > 0:
    for link in links:
        print 'Title: %s' % link['linktitle']
        print ‘Description: %s’ % link['linkdescription']
        print ‘URL: %s’ % link['linkurl']
        print ‘Submitted On: %s\r\n’ % link['linkpub_date']
If you read the post, you’ll find out how to get a list of a users friends, fans, who the user is a fan of and links posted by the users friends!


Loading Mahalo Top 7...