From 77f1d210dfd44f5b6c33cc58150b633643621bb0 Mon Sep 17 00:00:00 2001 From: vunhat_minh Date: Fri, 11 Jul 2014 15:30:16 +0900 Subject: [PATCH] iot support Python 3 --- rainbowstream/c_image.py | 4 ++-- rainbowstream/draw.py | 6 +++--- rainbowstream/py3patch.py | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/rainbowstream/c_image.py b/rainbowstream/c_image.py index 7922623..154552d 100644 --- a/rainbowstream/c_image.py +++ b/rainbowstream/c_image.py @@ -40,9 +40,9 @@ def image_to_display(path,start=None,length=None): i = i.resize((width, height), Image.ANTIALIAS) height = min(height, c['IMAGE_MAX_HEIGHT']) - for y in xrange(height): + for y in range(height): sys.stdout.write(' ' * start) - for x in xrange(width): + for x in range(width): p = i.getpixel((x, y)) r, g, b = p[:3] pixel_print(rgb2short(r, g, b)) diff --git a/rainbowstream/draw.py b/rainbowstream/draw.py index fa276f4..a0c7911 100644 --- a/rainbowstream/draw.py +++ b/rainbowstream/draw.py @@ -257,8 +257,8 @@ def draw(t, iot=False, keyword=None, fil=[], ig=[]): for mu in media_url: try: response = requests.get(mu) - image_to_display(StringIO(response.content)) - except: + image_to_display(BytesIO(response.content)) + except Exception: printNicely(red('Sorry, image link is broken')) @@ -390,7 +390,7 @@ def show_profile(u, iot=False): if iot: try: response = requests.get(profile_image_url) - image_to_display(StringIO(response.content), 2, 20) + image_to_display(BytesIO(response.content), 2, 20) except: pass else: diff --git a/rainbowstream/py3patch.py b/rainbowstream/py3patch.py index e1eec6e..543b9a1 100644 --- a/rainbowstream/py3patch.py +++ b/rainbowstream/py3patch.py @@ -5,9 +5,9 @@ import sys # StringIO module try: - from StringIO import StringIO + from StringIO import StringIO, BytesIO except: - from io import StringIO + from io import StringIO, BytesIO # raw_input and map functiion behaviour if sys.version[0]=="3": -- 2.25.1