Вопрос

I'm a bit of a novice a python but was wondering how to create a loop so that the code below could be run over multiple twitter ids instead of just the '433016508592037888'?

I have so far:

import tweepy


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)

def get_retweet_count(tweet_id):
    tweet = api.get_status(tweet_id)
    return tweet.retweet_count

print get_retweet_count( '433016508592037888')

any help would be great.

Это было полезно?

Решение

If you had the id's in a list:

ex: id_list = [id, id, id, id, id] # imagine those are id numbers :)

then you could do something like:

for id in id_list:
    print get_retweet_count(id)

for info on for loops and python loops in general, click here and here(codeacademy, python tutorials) and google ;)

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top