Skip to content

Instantly share code, notes, and snippets.

@laiso
Created June 9, 2010 19:18
Show Gist options
  • Save laiso/432025 to your computer and use it in GitHub Desktop.
Save laiso/432025 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# coding: utf-8
import os
import urllib2
from cStringIO import StringIO
import webbrowser
import Image
OQUNOKUN_URL = 'http://a1.twimg.com/profile_images/63752576/ee_mini.gif';
TMP_DIR = os.path.abspath(os.path.curdir)
TMP_IMAGE = "okunoqun.gif"
IMAGE_SIZE = (50, 50)
def safe_oqunokun(url):
image = None
response = urllib2.urlopen(url, timeout=60)
if response.getcode() == 200 and response.headers.get('Content-Length') > 0:
buf = response.read()
image = Image.open(StringIO(buf))
image = image.resize(IMAGE_SIZE)
return image
def save_tmpdir(image):
path = os.path.join(TMP_DIR, TMP_IMAGE)
fp = file(path, 'w')
image.save(fp)
return path
def main():
image = safe_oqunokun(OQUNOKUN_URL)
path = save_tmpdir(image)
webbrowser.open_new_tab(path)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment