简体   繁体   English

向我的python twitter bot添加一会儿语句

[英]adding a while statement to my python twitter bot

I'm working on a python twitter script. 我正在研究python twitter脚本。 So far it works great, but I need to add a while statement to limit the number of unfollows (api calls) to less than 100. I have been working on this all day and I admit I'm new to python, I may be missing something simple but I have tried a handful of variations to no avail. 到目前为止,它的运行情况很好,但是我需要添加一个while语句以将取消关注(api调用)的数量限制为少于100。我整天都在工作,我承认我是python的新手,我可能缺少一些简单的东西,但是我尝试了一些变种都没有用。

#! /usr/bin/python
# -*- coding: utf-8 -*-

import tweepy
from keys import keys

SCREEN_NAME = keys['screen_name']
CONSUMER_KEY = keys['consumer_key']
CONSUMER_SECRET = keys['consumer_secret']
ACCESS_TOKEN = keys['access_token']
ACCESS_TOKEN_SECRET = keys['access_token_secret']
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET)
api = tweepy.API(auth)
followers = api.followers_ids(SCREEN_NAME)
friends = api.friends_ids(SCREEN_NAME)
for f in friends:
    if f not in followers:
        print "Unfollow {0}?".format(api.get_user(f).screen_name)
if raw_input("Y/N?") == 'y' or 'Y':
    api.destroy_friendship(f)

Add an unfollow counter and increment that counter when you make an unfollow call. 添加取消关注计数器,并在进行取消关注调用时增加该计数器。 Then check if the counter is less than 100 in addition to the 'y' answer. 然后,除了回答“ y”外,还检查计数器是否小于100。

#! /usr/bin/python
# -*- coding: utf-8 -*-

...code before for loop here...
unfollows = 0
for f in friends:
    if f not in followers:
        print "Unfollow {0}?".format(api.get_user(f).screen_name)
        input = raw_input("Y/N?")
        if (unfollows < 100) and (input == 'y' or input 'Y'):
            api.destroy_friendship(f)
            unfollows += 1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM