Created
March 3, 2011 21:33
-
-
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 protected]')
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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