The Artima Developer Community
Sponsored Link

Web Buzz Forum
Adding photos to my Ubuntu One contacts

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Stuart Langridge

Posts: 2006
Nickname: aquarius
Registered: Sep, 2003

Stuart Langridge is a web, JavaScript, and Python hacker, and sometimes all three at once.
Adding photos to my Ubuntu One contacts Posted: Jan 31, 2011 7:41 AM
Reply to this message Reply

This post originated from an RSS feed registered with Web Buzz by Stuart Langridge.
Original Post: Adding photos to my Ubuntu One contacts
Feed Title: as days pass by
Feed URL: http://feeds.feedburner.com/kryogenix
Feed Description: scratched tallies on the prison wall
Latest Web Buzz Posts
Latest Web Buzz Posts by Stuart Langridge
Latest Posts From as days pass by

Advertisement

We've recently added display of contact images to the Ubuntu One website, in preparation for starting to have images for all your contacts. Over the weekend, Andy Mabbett tweeted "I really, really, really wish @GoogleContacts would fetch Gravatars for all my contacts", and I thought: yeah, Ubuntu One should do that too. So, hopefully we'll be able to look at that on the U1 server so you automagically get images for all your contacts who have gravatars. (Obviously, the set of people who have friends with gravatars is fairly closely aligned with the set of people who are techies, but, well, I am, so worth a try.)

Anyway, we don't have the Ubuntu One servers doing this (yet? the bloke you want to convince that this is a good idea is beuno), but Ubuntu One contacts have the advantage that they're all synced down to your machine as well (hooray), so it's easy to do this on your computer now rather than wait for the Ubuntu One servers to do it. So, a quick script.

Note: this script uses the new undeprecated desktopcouch APIs in Ubuntu 11.04, which is not yet released. So it likely won't work for you right now unless you're already running Ubuntu natty.

from desktopcouch.application.server import DesktopDatabase
from desktopcouch.records.record import Record
import urllib, md5
db = DesktopDatabase("contacts")
for contact in db.get_records(create_view=True, record_type="http://www.freedesktop.org/wiki/Specifications/desktopcouch/contact"):
    # sigh, db.get_records doesn't get Records at all, it gets a ViewResult. And
    # we can't just wrap row.value in a Record because that doesn't get attachments.
    # So re-fetch the Record from the database.
    r = db.get_record(contact.value['_id'])
    emails = r.get("email_addresses", None)
    if emails:
        for email in emails:
            addr = email.get('address', None)
            if addr:
                if "photo" in r.list_attachments():
                    print "Email %s already has photo in contact record" % addr
                    continue
                print ("Checking addr %s in record id %s:" % (addr, r.record_id)),
                hsh = md5.md5(addr.lower()).hexdigest().lower()
                fp = urllib.urlopen("http://www.gravatar.com/avatar/%s?d=404&s=50" % hsh)
                if fp.getcode() == 404:
                    print "not found."
                else:
                    r.attach(fp.read(), "photo", fp.info().get("Content-Type", "image/jpeg"))
                    fp.close()
                    db.put_record(r)
                    print "found!"

And now I have little pictures next to 123 out of 939 of my contacts on the Ubuntu One website (and hopefully soon in Evolution and on my phone as well).

Read: Adding photos to my Ubuntu One contacts

Topic: Nokia X2-01: Affordable QWERTY Mobile Phone with Java Support Previous Topic   Next Topic Topic: Nokia E7 pinned for pre-orders at Expansys for £495; Hitting UK in April

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use