Archive for June, 2008
Accessing Flickr Photos with Python
Flickr lists few python libraries to access its API. Of these, I choose Beej’s Python Flickr API. Probably the reason being it had extensive documentation (and it appeared first!).
Choosing the library was only one part. I had to spend most of the time (almost the whole of today) reading through the Flickr API. Once you understand the API, it becomes easy.
My requirement for S-I-P is pretty simple. Given a photo id, I need photo details (title, description), EXIF details and size details (thumbnail, original). To access Flickr API, you need to apply for a API Key.
Here is the simple program to access Flickr Info given a photo id. Most of it should be self explanatory. For more details, read through Flickr API documentation.
I’m still, relatively, a newbie in Python and Django. So if you think there could be a better way to do this, feel free to leave a comment.
def get_photo_info(api_key, photo_id):
f = flickrapi.FlickrAPI(api_key)
info=f.photos_getInfo(photo_id=photo_id)
title = info.photo[0].title[0].text
desc = info.photo[0].description[0].text
#url = info.photo[0].urls[0].url[0].text
tags = ' '.join(["%s" % (tag.text) for tag in info.photo[0].tags[0].tag])
exif = f.photos_getExif(photo_id=photo_id)
model = exif.photo[0].exif[1].raw[0].text
date_taken = exif.photo[0].exif[2].raw[0].text
exposure = exif.photo[0].exif[4].raw[0].text
aperture = exif.photo[0].exif[5].clean[0].text
exposure_prg = exif.photo[0].exif[6].clean[0].text
iso = exif.photo[0].exif[7].raw[0].text
exif_details = dict(model=model, date_taken=date_taken, exposure=exposure, aperture=aperture, exposure_prg = exposure_prg, iso=iso)
#getSize gets both size (thumbnails etc) and corresponding urls
sizes = f.photos_getSizes(photo_id=photo_id, format='json')
#there should be a better way to do the below
#flickr returns jsonflickrapi(....) as string
#i am retriving the values
sizes = simplejson.loads(sizes[14:-1])['sizes']['size']
for size in sizes:
if size.has_key('label'):
if size['label'] == 'Square':
thumb_url = size['url']
thumb_height = size['height']
thumb_width = size['width']
thumb_source = size['source']
if size['label'] == 'Large':
photo_url = size['url']
photo_height = size['height']
photo_width = size['width']
photo_source = size['source']
thumb_details = dict(url=thumb_url, height=thumb_height, width = thumb_width, source=thumb_source)
photo_details = dict(url=photo_url, height = photo_height, width = photo_width, source=photo_source)
return dict(title=title, desc=desc, tags = tags, exif=exif_details, thumb=thumb_details, photo=photo_details)
Related Links:
Flickr API
Say In Pixels – a photoblog in Django
I love to take photos. And show off!
The problem is I don’t take good photos. To take good photos, I need to take lots of photos. I will take lots of photos, if I can show off. To show off, I need an easy to use application which fits my bill. See my problem?
To host a photoblog, one needs enormous disk space which demands enormous money.
Okay there is Flickr (leaving aside Microsoft’s attempt to mess it up). But Flickr allows only members to comment. And it is not well suited as a photoblog.
So I decided to write a photoblog on my own. It is easier to code it on my own rather than complaining about all the existing ones. (May be someone else will complain about mine. But then, that would indicate that mine became popular!)
So here are the feature list that my photoblog will have:
- Will be Django based – Cool way to learn Django. If I can’t use technology to solve my problem, how can I use it to solve other’s problems.
- Flickr Integration – I’ll keep Flickr as primary storage.
- Tagging – Categories are one dimensional. Lets get away from it. Read more at Organize Pictures. How cool it would be if EXIF data also is used as tags?
- All other generic blog features – like comments, archives and the rest.
- PixelPost in Django? – # 1 photoblog application. But that is in PHP. Can I match it in features – especially easy to install? – and in popularity?
- Hosted in Google – Where else?
Am sure to pull through s-i-p. Only time will tell if I become a better photographer.
Words that changed my life
Recently I read an article titled, ‘The Best Advice I Ever Got’ in Leading Blog. That triggered a walk through the memory lane to capture the best advice I got. There were so many good advices that came to my mind. But only one stood out; that was the one that changed my life, forever.
Why it mattered?
I will get to those ‘magical words’ in a minute. But let me first tell you why it mattered so much to me.
As a child I had developed severe inferiority complex – about my appearance, about my inability to speak English and about many aspects of life. Though it didn’t have much impact on my curricular life – I managed to be among the top 10 students in class – it considerably impacted my interpersonal life. I would literally run away from anyone and everyone, always imagining that no one would be interested to talk to me. That turned into a vicious cycle – I didn’t speak to anyone due to inferiority complex; so I had very few friends; because I had few friends I would feel still inferior.
Because I studied well, my parents didn’t notice anything wrong. In fact no one noticed anything wrong. It was attributed to my personality.
It is true that in the early days it didn’t have much impact on my studies. However as I started loosing self-esteem, it showed up on my progress card. My ranks started falling down (which again aggravated the feeling).
With such inflated inferiority complex, I entered college.
Those miraculous words
What I saw in college didn’t help, everywhere I saw rich and handsome guys who were speaking English fluently. Or I thought so. I drowned still further in my low-esteem.
I wouldn’t know if my college-mate ‘Arun Edwin’ noticed anything wrong; or were they impromptu words, but he uttered those magical words:
You’re inferior to none and superior none; You are unique.
Those words hit me.
That was it. Those were the exact words that I had to hear. Yes true, I am inferior to none. I am what I am. What a revelation! What followed was a magical transformation. I was still the black, village boy who can’t speak proper English. But my perspective changed – ‘I am unique’.
The Impact
I’m looking back after about 15 years.
It is not a simple change; it is a heavenly transformation – none of my current colleagues will ever believe that I once suffered from inferiority complex. I don’t feel ‘threatened’ by ‘handsome’ guys anymore . I can strike a conversation with ease.
And my English improved very well. I am confident of writing articles, proposals and similar materials. I’m not (yet) perfect, but I keep improving myself. I dream of writing for journals like ‘HBS working knowledge’.
Not just the first part of advice but the second part too had a profound impact – not superior anyone. Even when I’ve tasted success after success, I keep repeating those words to myself. As a matter of fact, every success humbles me – I realize that I could’ve been a total failure in life; so I ensure that I don’t spoil my success with haughtiness.
If you feel inferior for any reason, however genuine they might seem, repeat those words with me:
You are inferior to none; You are superior to none; You are unique.
Those words will bring magical results into your life, as it brought to mine.
A free (but superb) Django hosting
Ever since I stared to learn Django, I’ve looking for a web-host to host the apps that I develop – so that I can learn the every bit of the learning chain: from design until hosting. As it was for learning purpose, I didn’t want to pay heavily for it. So primarily I was looking for some free hosting service.
I came to know via Django Google Groups that bells-n-whistles provide a fee hosting service. I sent them a mail via their contact form. They setup the free domain and sent me a mail regarding the details. Their free hosting access is only via FTP.
I had starting glitches with the hosting. Every time I sent them a mail, they were very prompt in answering back. Being a newbie into Django (especially its hosting), I probably asked silly and annoying questions. Not minding, they replied back with answers – simple yet to the point.
There is no detailed documentation on their site. So here is what worked for me.
Here is the snippet of settings.py
DATABASE_ENGINE = 'sqlite3'
DATABASE_NAME = os.path.join(PROJECT_DIR, 'sol.db')
MEDIA_ROOT = '%s' % PROJECT_DIR
MEDIA_URL = 'media/'
ADMIN_MEDIA_PREFIX = '/media/'
TEMPLATE_DIRS = (
r'%s/templates/sol' % PROJECT_DIR,
r'%s/templates' % PROJECT_DIR,
r'%s/templates/admin' % PROJECT_DIR,
)
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.admin',
'sol',
)
As you can see, I am using sqlite instead of their default db PostgreSQL. As it is a demo db, it works okay for me.
Then transfer both application templates and admin templates to templates directory. Transfer css files to media directory. If you have file uploads (like images or avatars), they should be within media directory as well.
Of course since it is a free hosting, you need to add a link to their site. For the free service that they provide, it is expected. If I continue to learn Django (I’ll be), then I will most probably, go with them for hosting.
You can visit their site at: bells-n-whistles. The one that I’m hosting is at: http://cephire.bells-n-whistles.net. (Since it is a demo and just setup, there is not much there. Hope to add over the time. It is a Twitter clone. If you want to try it out, use jjude/jjude for user id/password).
5 questions you should ask to be effective
Recently my brother-in-law was promoted to be a manager. As we discussed on his new role, I recollected the years that I myself have been one and reflected on what made me effective.
What follows is a set of questions that I ask myself whenever I take up a new task. In fact I go over these questions (almost) on a daily basis to keep myself effective.
What is expected of me?
To be effective, first and foremost, you need to be clear of what is expected of you – said otherwise, the output of the task given to you.
- Mock Screens
- Detailed Project Plan
- Working Demo
- Presentation on Sales Process
Get this clear and precise. Else you’ll be working hard to produce a wrong output – a disappointment to you and to your boss (or the one who requested it).
What is the priority?
Asking this question serves two purposes.
First one is the obvious one. Given the list of tasks that I’m already doing, where does this fit in. Should I jump in right now or can it wait. Learn to distinguish urgent tasks from important tasks.
You may not get an answer always to the second type, but it helps: where does this fit in the grand scheme – within the project, within the department, within the organization. Knowing the answer for this question, will help you understand the importance of your work.
What is the timeline?
Sometimes you’ll be asked to give a timeline; and sometimes it will be given to you. In both cases, you should be certain that you can deliver within the specified time period.
In reality, situation will almost always demand you to squeeze timelines. Yet, don’t confuse effectiveness (delivering what is requested) with efficiency (delivering by using less resources). Unless you’ve mastered effectiveness, you can’t be efficient.
What do I need?
You need to be expressive and explicit in this area. Be specific about the need to complete the task – 2 technical architects, a video conference link, 1 GB RAM. Whatever be it; be specific.
Often times in a postmortem study (when it is a failure) we’ll say that I could’ve completed the task successfully only if I was given a, b and c. And invariably the boss (or other stakeholder) will question, ‘why didn’t you say so?’.
What can go wrong?
Oh! this is a big part of being effective. Mostly this comes from experience; but intuition can help. The least expected will go wrong to make the trivial tasks urgent.
How much ever you are prepared, things will still go wrong; but that is no excuse for you not to be prepared. Though it is practically impossible to think of ‘all’ that can go wrong, you should have a ‘Plan B’ for the obvious ones. As you grow in experience, the list of the ‘obvious ones’ will increase and it will increase your instances of being effective.
Learn to apply these principles in the little tasks assigned to you; then they will be imbibed in you to accomplish greater tasks.
Go forth and be effective!