2017-08-22 00:09:54 +02:00
|
|
|
#!/usr/bin/env python3
|
2016-09-20 21:28:39 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
import tweepy
|
|
|
|
|
|
|
|
# Nothing wrong with a nice enterprisy class name, right?
|
|
|
|
class RetweetingStreamListener(tweepy.StreamListener):
|
|
|
|
|
|
|
|
|
|
|
|
def on_status(self, status):
|
2017-08-22 00:09:54 +02:00
|
|
|
print("[Info] %s - %s" % (status.user.screen_name, status.text))
|
2016-09-20 21:28:39 +02:00
|
|
|
|
|
|
|
if not hasattr(status, 'retweeted_status'):
|
|
|
|
status.retweet()
|
2017-08-22 00:09:54 +02:00
|
|
|
print("[Info] Retweeted!")
|
2016-09-20 21:28:39 +02:00
|
|
|
|
|
|
|
|
2017-08-22 00:09:54 +02:00
|
|
|
print("-----------------------------------------")
|
2016-09-20 21:28:39 +02:00
|
|
|
|
|
|
|
|
|
|
|
def on_error(self, status_code):
|
|
|
|
# Rate limiting
|
|
|
|
if status_code == 420:
|
2017-08-22 00:09:54 +02:00
|
|
|
print("[Error] Got Error 420, rate limiting in effect")
|
2016-09-20 21:28:39 +02:00
|
|
|
#returning False in on_data disconnects the stream
|
|
|
|
return False
|
|
|
|
|
2017-08-22 00:09:54 +02:00
|
|
|
print("[Error] Got status code %d" % status_code)
|