This file contains 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
#!/usr/bin/python | |
# -*- coding: utf-8 -*- | |
'Execute from command line or include in cron' | |
import tweepy, sys | |
'Follow the instructions at: http://talkfast.org/2010/05/31/twitter-from-the-command-line-in-python-using-oauth/' | |
# Twitter oAuth | |
CONSUMER_KEY = '' | |
CONSUMER_SECRET = '' | |
ACCESS_KEY = '' | |
ACCESS_SECRET = '' | |
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET) | |
"Stage 1: Authorize app" | |
if ACCESS_KEY == '': | |
print 'Follow the instructions at: http://talkfast.org/2010/05/31/twitter-from-the-command-line-in-python-using-oauth/' | |
auth_url = auth.get_authorization_url() | |
print 'Please authorize: ' + auth_url | |
verifier = raw_input('PIN: ').strip() | |
auth.get_access_token(verifier) | |
print "ACCESS_KEY = '%s'" % auth.access_token.key | |
print "ACCESS_SECRET = '%s'" % auth.access_token.secret | |
else: | |
auth.set_access_token(ACCESS_KEY, ACCESS_SECRET) | |
api = tweepy.API(auth) | |
# List of your friends | |
friends = api.friends_ids() | |
try: | |
f = open('eow.lastid', 'r') | |
since_id = int(f.read()) | |
f.close() | |
except IOError: | |
since_id = 1 | |
# Keep log | |
f = open('eow.log', 'a+') | |
for result in api.search(u"краят на света", lang='bg', rpp=100, since_id=since_id): | |
if result.from_user_id in friends: | |
try: | |
# shut up! | |
api.destroy_friendship(result.from_user_id) | |
f.write("Blocked: "+result.from_user+" for "+result.text.encode('utf-8')+"uid:"+str(result.from_user_id)+"\n") | |
print "Block:",result.from_user | |
except: | |
f.write("Unable to block: "+result.from_user+" for "+result.text.encode('utf-8')+"\n") | |
f.close() | |
# Persist | |
f = open('eow.lastid', 'w+') | |
f.write(str(result.id)) | |
f.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment