Skip to content

Instantly share code, notes, and snippets.

@peio
Created December 17, 2012 20:15
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save peio/4321739 to your computer and use it in GitHub Desktop.
#!/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