mercredi 4 janvier 2017

Pythonic way to write a series of non-cascading if statements

So I have this code I wrote to read from information from twitters REST API using tweepy and I'd like to collect a lot of information without exceeding the rate limit. This question is more of a conceptual one than tweepy-related. So far this is the only way i've thought of doing it:

for i, tweet in enumerate(tweepy.Cursor(api.user_timeline, screen_name = "@twitter").items(1400)):
    print(i, tweet.author.name)
    if i == 200:
        time.sleep(180)
    if i == 400:
        time.sleep(180)
    if i == 600:
        time.sleep(180)
    if i == 800:
        time.sleep(180)
    if i == 1000:
        time.sleep(180)
    if i == 1200:
        time.sleep(180)
    if i == 1400:
        sys.exit()

But rather than writing a bunch of if statements, is there a more pythonic way this can be written? Or if it isn't broken don't fix it?

Aucun commentaire:

Enregistrer un commentaire