Skip to content

Instantly share code, notes, and snippets.

@seadowg
Created March 3, 2011 21:33
Show Gist options
  • Save seadowg/853634 to your computer and use it in GitHub Desktop.
Save seadowg/853634 to your computer and use it in GitHub Desktop.
Python script for setting your Ubuntu user pic as your Gravatar (command: 'python grav.py email@example.com')
import hashlib, urllib2, sys, os
class Gravatar:
def __init__(self, email):
self.email = email
self.hash = hashlib.md5(self.email.lower()).hexdigest()
def get(self):
try:
remote = urllib2.urlopen('http://gravatar.com/avatar/' + self.hash).read()
return remote
except urllib2.URLError:
print 'Can\'t talk to Gravater. Are you connected to the internet?'
def main():
try:
gravatar = Gravatar(sys.argv[1])
remote = gravatar.get()
local = open(os.path.expanduser('~/.face'), 'w')
local.write(remote)
local.close()
except IndexError:
print 'No email specified!'
except IOError:
print 'Can\'t save avatar. FILE PERMISSIONS!'
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment