Skip to content

Instantly share code, notes, and snippets.

@jpmens
Forked from koehntopp/tweepyfollowers.py
Created September 20, 2017 17:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jpmens/55f35dc13ca2aced972e0518d6910640 to your computer and use it in GitHub Desktop.
Save jpmens/55f35dc13ca2aced972e0518d6910640 to your computer and use it in GitHub Desktop.
Tweepy test: Check for posters with hashtag that follow a certain user and block them
# Tweepy API documentation: http://docs.tweepy.org/en/latest/index.html
# Vorher mit 'pip install tweepy' Tweepy installieren
# Twitter App registrieren unter https://apps.twitter.com/
import tweepy
auth = tweepy.OAuthHandler("Consumer Key (API Key)", "Consumer Secret (API Secret)")
auth.set_access_token("Access Token", "Access Token Secret")
api = tweepy.API(auth)
# The user that people follow
auser = api.get_user("TwitterHandle")
auserid=auser.id
# Iterate through 100 posts with a certain hashtag, may hit API throttling eventually (15 minutes wait)
for tweet in tweepy.Cursor(api.search, q="#hashtag", count=10, include_entities=True).items(100):
userid = tweet.user.id
userfollower = tweet.user.followers_count
username = tweet.user.name.encode('utf-8', errors = 'ignore')
# Does the tweet author follow the user defined above?
status = api.show_friendship(source_id=userid, target_id=auserid)
# If he does print
if status[0].following:
print username + " folgt " + auser + "(" + str(userfollower) + "Followers)"
# Block the user
if api.create_block(id = userid):
print " " + username + " blocked successfully"
@PRABHULINGAYYA
Copy link

unable to import SensoreTagcc2650 as sensortag

help me out please
thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment