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 json
import os
@ -362,20 +364,24 @@ def get_stream(ctx, locations, track, file):
file.close()
@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
def read_stream(ctx, file):
for tweet in utils.read_file(file, tail=True):
print('{timestamp_ms}- @{screen_name}: {text}'.format(timestamp_ms=tweet['timestamp_ms'], screen_name=tweet['user']['screen_name'], text=tweet['text']))
def read_stream(ctx, file, tail):
for tweet in utils.read_file(file, tail=tail):
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')
@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.pass_context
def tags_stream(ctx, file, limit):
c = utils.get_hashtags(utils.read_file(file))
for count, tag in c.most_common(limit):
print('{} - {}'.format(count, tag))
print(u'{} - {}'.format(count, tag))
if __name__ == '__main__':

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

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

Loading…
Cancel
Save