本文整理汇总了Python中tweepy.AppAuthHandler方法的典型用法代码示例。如果您正苦于以下问题:Python tweepy.AppAuthHandler方法的具体用法?Python tweepy.AppAuthHandler怎么用?Python tweepy.AppAuthHandler使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tweepy
的用法示例。
在下文中一共展示了tweepy.AppAuthHandler方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import tweepy [as 别名]
# 或者: from tweepy import AppAuthHandler [as 别名]
def __init__(self,
consumer_key, consumer_secret,
access_token=None, access_token_secret=None,
rapidapi_key=None,
**kwargs):
self.consumer_key = consumer_key
self.consumer_secret = consumer_secret
self.access_token_key = self.access_token = access_token
self.access_token_secret = access_token_secret
self.wait_on_ratelimit = kwargs.get('wait_on_ratelimit', False)
self.rapidapi_key = rapidapi_key or kwargs.get('mashape_key')
if self.access_token_key is None or self.access_token_secret is None:
auth = tweepy.AppAuthHandler(
self.consumer_key, self.consumer_secret)
else:
auth = tweepy.OAuthHandler(
self.consumer_key, self.consumer_secret)
auth.set_access_token(
self.access_token_key, self.access_token_secret)
self.twitter_api = tweepy.API(
auth,
parser=tweepy.parsers.JSONParser(),
wait_on_rate_limit=self.wait_on_ratelimit,
)
self.api_url = kwargs.get('botometer_api_url',
'https://botometer-pro.p.rapidapi.com')
self.api_version = kwargs.get('botometer_api_version', 2)
示例2: _get_tweepy_appauth_handler
# 需要导入模块: import tweepy [as 别名]
# 或者: from tweepy import AppAuthHandler [as 别名]
def _get_tweepy_appauth_handler(self, oauth_dict):
try:
return tweepy.AppAuthHandler(oauth_dict["consumer_key"], oauth_dict["consumer_secret"])
except TweepError:
print TweepError
示例3: tweepy_auth
# 需要导入模块: import tweepy [as 别名]
# 或者: from tweepy import AppAuthHandler [as 别名]
def tweepy_auth(cred, mode):
auth = None
if mode == 'user':
auth = tweepy.OAuthHandler(cred['consumer_key'], cred['consumer_secret'])
auth.set_access_token(cred['access_token_key'], cred['access_token_secret'])
elif mode == 'app':
auth = tweepy.AppAuthHandler(cred['consumer_key'], cred['consumer_secret'])
return tweepy.API(auth, wait_on_rate_limit=False) if auth else None
# ----------------------------------------------------------
# -------------------- Account Manager ---------------------
# ----------------------------------------------------------
示例4: main
# 需要导入模块: import tweepy [as 别名]
# 或者: from tweepy import AppAuthHandler [as 别名]
def main():
consumer_key = os.environ.get('TWEEPY_CONSUMER_KEY')
consumer_secret = os.environ.get('TWEEPY_CONSUMER_SECRET')
api_auth = AppAuthHandler(consumer_key, consumer_secret)
app_api = API(api_auth, wait_on_rate_limit_notify=True,
wait_on_rate_limit=True)
# Set up the database
database_path = 'amplification.db'
engine = create_engine('sqlite:///{}'.format(database_path))
session_factory = sessionmaker(bind=engine)
session = scoped_session(session_factory)
Base.metadata.create_all(engine)
args = parse_args()
try:
crawler = Queue()
crawler.put(args.seed_acount)
accounts_seen = set()
while not crawler.empty():
account_id = crawler.get()
tweets = get_tweets(app_api, account_id)
tweet_crawl_date = datetime.utcnow()
prioritized_list = process_tweets(tweets)
for item in prioritized_list:
tweet = item[1]
author = tweet['user']
logger.info('Found {} amplified tweets from {}'.format(
len(prioritized_list), author['screen_name']))
tweet_node = add_tweet_node(session, tweet['id'], author['id'],
author['screen_name'], tweet['text'],
tweet_crawl_date)
retweeters = get_retweeters(app_api, tweet['id'])
for retweeter in retweeters:
retweeter_id = retweeter['id']
if not is_retweet_bot(app_api, retweeter_id):
continue
logger.info('\tPotential retweet bot: {}'.format(retweeter['screen_name']))
account_crawl_date = datetime.utcnow()
account_node = add_account_node(session, retweeter['id'],
retweeter['screen_name'],
account_crawl_date)
add_edge(session, account_node, tweet_node)
if retweeter_id in accounts_seen:
continue
accounts_seen.add(retweeter_id)
crawler.put(retweeter_id)
except KeyboardInterrupt:
print('CTRL+C received... shutting down')