Add script example to block users, takes input from the command line or interactively.

This commit is contained in:
Ben McGinnes 2014-08-05 22:41:12 +10:00
parent af1a68eecb
commit 8e44989c01

20
examples/block_user.py Normal file
View file

@ -0,0 +1,20 @@
from twython import Twython, TwythonError
# Optionally accept user data from the command line (or elsewhere).
#
# Usage: block_user.py A_Twitter_Troll
import sys
if len(sys.argv) >= 2:
target = sys.argv[1]
else:
target = raw_input("User to follow: ") # For Python 3.x use: target = input("User to follow: ")
# Requires Authentication as of Twitter API v1.1
twitter = Twython(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET)
try:
twitter.create_block(screen_name=target, skip_status="true")
except TwythonError as e:
print(e)