unicode correctness + bugfix images reverse

This commit is contained in:
Johann Dreo 2016-07-29 15:59:30 +02:00
commit 913e0b552e

View file

@ -19,7 +19,7 @@ def write(data, stream = sys.stdout):
Write "data" on the given stream, then flush, silently handling broken pipes.
"""
try:
stream.write(data)
stream.write(data.encode(locale.getpreferredencoding(True) or "utf-8"))
stream.flush()
# Silently handle broken pipes
@ -52,10 +52,10 @@ def setup_counter( data, asked ):
data = list(data)
nb = len(data)
# " int/int"
counter_size = len(str(nb))*2 + 1 + 1
counter_size = len(str(nb).encode("utf-8").decode("utf-8") )*2 + 1 + 1
for i,line in enumerate(data):
counter = " %i/%i" % (i+1,nb)
counter = u" %i/%i" % (i+1,nb)
curmax = asked.max_len - len(counter)
if len(line) > curmax:
if asked.ignore:
@ -109,7 +109,8 @@ def on_stdout( data, asked, endline="\n" ):
if asked.independent:
yield line
else:
yield i + " " + line
l = u"%i %s" % (i,line)
yield l
#
@ -122,6 +123,7 @@ def on_twitter( data, api, asked, endline="\n" ):
prev_status_id = None
images = asked.twitter_images
if images:
images.reverse()
for line in lines:
@ -248,7 +250,6 @@ if __name__=="__main__":
asked = parser.parse_args()
# Setup
if asked.setup:
configfile = asked.api+".conf"