sudo apt-get install python-tweepy
. import tweepy, webbrowser CONSUMER_KEY = 'paste your Consumer Key here' CONSUMER_SECRET = 'paste your Consumer Secret here' auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET) auth_url = auth.get_authorization_url() webbrowser.open(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
#coding: utf-8 import oauth, tweepy, sys, locale, threading from time import localtime, strftime, sleep replyed=[''] search_reply_words={'':' , "", .','':' , "", .'} update_time=60 # def Tweet(twit,id_reply): if len(twit)<=140 and len(twit)>0: api.update_status(twit,id_reply) # ( ) return True else: return False def init(): # global api #consumer_key = "" #consumer_secret = "" #access_key="" #access_secret="" auth = tweepy.OAuthHandler(consumer_key, consumer_secret) auth.set_access_token(access_key, access_secret) api=tweepy.API(auth) class TwiBot(threading.Thread): def __init__ (self, keyword,answer): self.keyword = keyword self.answer=answer threading.Thread.__init__(self) def run (self): global replyed,api request=api.search(self.keyword) # for i in request: if i.from_user!='thevar1able' and i.id not in replyed: # ... try: Tweet('@'+i.from_user+self.answer,i.id) #... print strftime('[%d/%m %H:%M:%S]',localtime())+' Reply to @'+i.from_user+'('+str(i.from_user_id)+')' except: print strftime('DUP [%d/%m %H:%M:%S]',localtime())+' Reply to @'+i.from_user+'('+str(i.from_user_id)+')' replyed.append(i.id) return True init() # while not False: # for word in search_reply_words: TwiBot(word, search_reply_words[word]).start() # print strftime('[%d/%m %H:%M:%S]',localtime())+' Updating for word "'+str(word)+'"...' sleep(1) sleep(update_time)
Source: https://habr.com/ru/post/127237/
All Articles