Data Unbound

Helping organizations access and share data effectively. Special focus on web APIs for data integration.

January 1st, 2009

Getting started with flickrapi

Based on reading the  Python FlickrAPI, I wrote a simple example using the flickrapi library:

import flickrapi
API_KEY = '[API_KEY]'
API_SECRET = '[API_SECRET]'

if __name__ == '__main__':
    # instantiate the flickr object with the API_KEY, SECRET to return ElementTree entities
    flickr = flickrapi.FlickrAPI(api_key=API_KEY,secret=API_SECRET,format='etree')
    photos = flickr.photos_search(user_id='73509078@N00', per_page='10')

    if photos.attrib['stat']:
        for photo in photos.find('photos').getiterator('photo'):
            id = photo.attrib['id']
            secret = photo.attrib['secret']
            server_id = photo.attrib['server']
            farm_id = photo.attrib['farm']
            user_id = photo.attrib['owner']
            # calculate the thumbnail URL and photo URL
            # http://www.flickr.com/services/api/misc.urls.html
            thumbnail_url = "http://farm%s.static.flickr.com/%s/%s_%s_t.jpg" \
                            % (farm_id, server_id, id, secret)
            photo_url = "http://www.flickr.com/photos/%s/%s"  % (user_id, id)
            print thumbnail_url, photo_url
December 31st, 2008

Django hosting options?

Although it seems that you can host Django on dreamhost (Django – DreamHost and JeffCroft.com: Setting up Django on Dreamhost), I might be looking for another host for Django, such as (mt) Media Temple, which is what is used by Django creator Adrian Holovaty for his EveryBlock project.

December 31st, 2008

SWIG

Although I plan to be programming primarily  in Python (and JavaScript)  this next year, I don't want to forget about C/C++.  I hope to have an opportunity to use SWIG at some point to connect high-speed code in C/C++ with Python code:

SWIG is an interface compiler that connects programs written in C and C++ with scripting languages such as Perl, Python, Ruby, and Tcl. It works by taking the declarations found in C/C++ header files and using them to generate the wrapper code that scripting languages need to access the underlying C/C++ code. In addition, SWIG provides a variety of customization features that let you tailor the wrapping process to suit your application.

December 31st, 2008

Time to study Python 3.0?

I had been vaguely following Python 3 when Python 3.0 final was released on December 3, 2008. I decide to start coming to terms with what this new and intentionally non-backwards compatible version of Python means by printing out What’s New In Python 3.0 — Python v3.0 documentation and Linux.com :: Python 3.0 makes a big break. My current conclusion from reading the articles: I should learn Python 3.0 in the background but make mastery of Python 2.x the priority for at least the next several years.

December 30th, 2008

listing applications installed in Windows XP with Python

The end of 2008 is approaching, making it an appropriate time to take inventory of my life — which also includes a lot of  my computer-related stuff.   In addition to cleaning up my office, I'm also cleaning up my Lenovo Thinkpad T60p, my primary work computer, whose drive has been close to its 100 GB limit for some time now.  To help me spot the disk hogs, I've been running WinDirStat – Windows Directory Statistics.

I'm also looking through all the programs I've installed over the years, lot of which I've not used and should be uninstalled to save space!  Although I've been using Windows XP's Control Panel's Add/Remove Program, I would also like to have some automated way to inventory my system — hence I started looking for Python code to do so.

I found the following code in List of all installed applications (XP)?:

import win32api, win32con, pywintypes

appKey = win32api.RegOpenKeyEx(win32con.HKEY_LOCAL_MACHINE, \
           'SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths', 0, win32con.KEY_READ)
sklist = win32api.RegEnumKeyEx(appKey)

for skey in sklist:
     print skey[0]

     try:
          wPath = win32api.RegQueryValue(appKey, skey[0])
          print '    ' + wPath
     except pywintypes.error,details:
          print '### Error [pywintypes.error]: ' + details[2]

win32api.RegCloseKey(appKey)

The code seems to work. The response to query for a better technique pointed to Tim Golden's Python Stuff: wmi. WMI looks cool and worthwhile following up with, especially because of what seems to be excellent documentation in the form of wmi Tutorial and wmi Cookbook.

|