More about Alcides Fonseca
Go Back

Some improvements

Written by Alcides Fonseca at 1184499994

In the last days, I’ve been changing some stuff in this blog. As requested by some users, I made a RSS feed for comments, so you can be warned when new comments are made. It was also meant to work with Bloppy, but there is some weird thing going on, I will correct with Mário Lopes, it’s author.

I’ve also added Gravatars to the comments. For those who don’t know what it is, it’s simply a 80×80px avatar that is associated with your email address and used in a lot of blog systems. As in the official website, there was PHP, PERL, ColdFusion and JAVA implementation, but no Python, here it goes:

_url_encre = re.compile(r\"[^A-Za-z0-9_.!~*()-]\")
_url_decre = re.compile(r\"%([0-9A-Fa-f]{2})\")
_html_encre = re.compile(\"[&<>\\\"'+]\")
_html_encodes = { \"&\": \"&\", \"<\": \"<\", \">\": \">\", \"\\\"\": \""\",\"'\": \"'\", \"+\": \"+\" }

def url_encode(raw):
    if not isinstance(raw, unicode):
        raw = str(raw)
    return re.sub(_url_encre, lambda m: \"%%%02X\" % ord(, raw)

def gravatar(email,size='80',rating='R',default=''):
    import md5
    return "" + str(gr.hexdigest()) + "&amp;size=" + str(size) + "&amp;rating=" + str(rating) + "&amp;default=" + url_encode(str(default))

And this code is part of my Pungi webmicroframework I think I might release in September. Let's see how it goes.

Yet regarding Gravatars, I was thinking of adding it to ejaki, but the fact that an API is not available for creating gravatars is taking that idea out of my mind. Who knows, with Gravatar v2...

Note: I’ve been victim of a slow internet connection for this weekend. I blame SAPO and hope it will be restored as soon as possible :/