Last active
March 7, 2020 00:33
-
-
Save wmalarski/8f431d13d83ebb07015438472abf5d36 to your computer and use it in GitHub Desktop.
Blokada troll kont
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[TWEEPY] | |
access_token_secret = | |
consumer_secret = | |
consumer_key = | |
access_token = | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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