Fixed python2 compatibility issues (print!)

master
J. Fernando Sánchez 8 years ago
parent 4afdd6807d
commit c0309a1e52

@ -1 +1 @@
0.6.2 0.6.4

@ -1,3 +1,5 @@
from __future__ import print_function
import click import click
import json import json
import os import os
@ -362,20 +364,24 @@ def get_stream(ctx, locations, track, file):
file.close() file.close()
@stream.command('read') @stream.command('read')
@click.option('-f', '--file', help='File to read the stream of tweets from') @click.option('-f', '--file', help='File to read the stream of tweets from', required=True)
@click.option('-t', '--tail', help='Keep reading from the file, like tail', type=bool, default=False)
@click.pass_context @click.pass_context
def read_stream(ctx, file): def read_stream(ctx, file, tail):
for tweet in utils.read_file(file, tail=True): for tweet in utils.read_file(file, tail=tail):
print('{timestamp_ms}- @{screen_name}: {text}'.format(timestamp_ms=tweet['timestamp_ms'], screen_name=tweet['user']['screen_name'], text=tweet['text'])) try:
print(u'{timestamp_ms}- @{screen_name}: {text}'.format(timestamp_ms=tweet['timestamp_ms'], screen_name=tweet['user']['screen_name'], text=tweet['text']))
except (KeyError, TypeError):
print('Raw tweet: {}'.format(tweet))
@stream.command('tags') @stream.command('tags')
@click.option('-f', '--file', help='File to read the stream of tweets from') @click.option('-f', '--file', help='File to read the stream of tweets from', required=True)
@click.argument('limit', required=False, default=None, type=int) @click.argument('limit', required=False, default=None, type=int)
@click.pass_context @click.pass_context
def tags_stream(ctx, file, limit): def tags_stream(ctx, file, limit):
c = utils.get_hashtags(utils.read_file(file)) c = utils.get_hashtags(utils.read_file(file))
for count, tag in c.most_common(limit): for count, tag in c.most_common(limit):
print('{} - {}'.format(count, tag)) print(u'{} - {}'.format(count, tag))
if __name__ == '__main__': if __name__ == '__main__':

@ -74,7 +74,7 @@ class RestWorker(TwitterWorker):
api_class = Twitter api_class = Twitter
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs) super(RestWorker, self).__init__(*args, **kwargs)
self._limits = None self._limits = None
@property @property
@ -210,7 +210,7 @@ class StreamWorker(TwitterWorker):
api_class = TwitterStream api_class = TwitterStream
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs) super(StreamWorker, self).__init__(*args, **kwargs)
class StreamQueue(QueueMixin): class StreamQueue(QueueMixin):
worker_class = StreamWorker worker_class = StreamWorker

@ -104,7 +104,7 @@ def read_file(filename, tail=False):
if tail: if tail:
time.sleep(1) time.sleep(1)
else: else:
return line return
def get_users(wq, ulist, by_name=False, queue=None, max_users=100): def get_users(wq, ulist, by_name=False, queue=None, max_users=100):

Loading…
Cancel
Save