Added avatar support
This commit is contained in:
@ -4,7 +4,8 @@ import re
|
||||
import gtk, gobject
|
||||
from threading import Thread,RLock
|
||||
from twitter import Api
|
||||
from urllib2 import HTTPError,URLError
|
||||
from urllib2 import HTTPError,URLError,urlopen
|
||||
from avcache import AvCache
|
||||
|
||||
|
||||
class CustomApi(Api):
|
||||
@ -89,6 +90,11 @@ class GetTweets(ApiThread):
|
||||
except (HTTPError, URLError):
|
||||
statuses = None
|
||||
|
||||
# For each user id present, populate the AvCache with an image
|
||||
if statuses:
|
||||
for status in statuses:
|
||||
add_to_cache(status)
|
||||
|
||||
gtk.gdk.threads_enter()
|
||||
try:
|
||||
self.pane.update_window(statuses)
|
||||
@ -115,6 +121,10 @@ class GetSingleTweet(ApiThread):
|
||||
except (HTTPError, URLError):
|
||||
statuses = None
|
||||
|
||||
# In case we've never seen this user, grab their profile image
|
||||
for status in statuses:
|
||||
add_to_cache(status)
|
||||
|
||||
gtk.gdk.threads_enter()
|
||||
try:
|
||||
self.pane.update_window(statuses)
|
||||
@ -262,3 +272,21 @@ def dms_to_statuses(direct_messages):
|
||||
status.text = dm.text
|
||||
statuses.append(status)
|
||||
return statuses
|
||||
|
||||
|
||||
def add_to_cache(status):
|
||||
with AvCache().lock:
|
||||
hit = AvCache().map.has_key(status.user.screen_name)
|
||||
if not hit:
|
||||
try:
|
||||
url = urlopen(status.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[status.user.screen_name] = image
|
||||
except URLError:
|
||||
pass # Nothing needs be done, just catch & ignore
|
||||
|
Reference in New Issue
Block a user