moved add_to_cache to avcache.py and added the profile_image_url to results from searches and dms

This commit is contained in:
Anna 2010-05-18 10:50:15 -04:00
parent 324bd13120
commit 86af5ede96
2 changed files with 41 additions and 28 deletions

View file

@ -1,4 +1,6 @@
from threading import RLock
from urllib2 import URLError,urlopen
import gtk
class AvCache:
@ -38,3 +40,26 @@ class AvCache:
return setattr(self.__instance, attr, value)
# end class AvCache
def add_to_cache(user):
"""
This helping function takes a python-twitter User object, grabs the image
data from the image_url and adds it to the AvCache with the screen_name as
the key.
"""
with AvCache().lock:
hit = AvCache().map.has_key(user.screen_name)
if not hit:
try:
url = urlopen(user.profile.image_url)
data = url.read()
loader = gtk.gdk.PixbufLoader()
loader.write(str(data))
image = loader.get_pixbuf()
loader.close()
with AvCache().lock:
AvCache().map[user.screen_name] = image
except URLError:
pass # Nothing needs be done, just catch & ignore