Skip to content

Instantly share code, notes, and snippets.

@wmalarski
Last active March 7, 2020 00:33
Show Gist options
  • Save wmalarski/8f431d13d83ebb07015438472abf5d36 to your computer and use it in GitHub Desktop.
Save wmalarski/8f431d13d83ebb07015438472abf5d36 to your computer and use it in GitHub Desktop.
Blokada troll kont
[TWEEPY]
access_token_secret =
consumer_secret =
consumer_key =
access_token =
from __future__ import division
import tweepy
import configparser
config = configparser.ConfigParser()
config.read('config.ini')
access_token_secret = config['TWEEPY']['access_token_secret']
consumer_secret = config['TWEEPY']['consumer_secret']
consumer_key = config['TWEEPY']['consumer_key']
access_token = config['TWEEPY']['access_token']
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
user_tml_cnt = 200.
block_prop = 1./30.
class BlockListener(tweepy.StreamListener):
def on_status(self, status):
user = status.user
user_tml = api.user_timeline(id=user.id, count=user_tml_cnt)
user_tml_len = len(user_tml)
user_replies_cnt = sum(1 if tweet.in_reply_to_user_id else 0 for tweet in user_tml)
user_prop = (user_tml_len - user_replies_cnt) / user_tml_len
if user_prop < block_prop:
print 'Wypad pajacu! ', user.name, user_prop
api.create_block(id=user.id)
def on_error(self, status):
print status
if __name__ == "__main__":
listener = BlockListener()
myStream = tweepy.Stream(auth=api.auth, listener=listener)
# Blokowanie z mentions
# name = '@realDonaldTrump'
name = '@'+api.me().screen_name
myStream.filter(track=[name])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment