0
votes

Im trying to download tweets into a csv to train a bot but I'm stuck at this Indexerror. The error is in the last line:

    def download_tweets(
username=None,
limit=None,
include_replies=False,
include_links=False,
strip_usertags=False,
strip_hashtags=False,

# If a limit is specificed, validate that it is a multiple of 20
if limit:
    assert limit % 20 == 0, "`limit` must be a multiple of 20."

# If no limit specifed, estimate the total number of tweets from profile.
else:
    c_lookup = twint.Config()
    c_lookup.Username = username
    c_lookup.Store_object = True
    c_lookup.Hide_output = True
    if include_links is True:
        c_lookup.Links = "include"
    else:
        c_lookup.Links = "exclude"

    twint.run.Lookup(c_lookup)
    limit = twint.output.users_list[-1].tweets

Error message: in download_tweets limit = twint.output.users_list[-1].tweets IndexError: list index out of range

This Happens when your list is empty , twint.output.users_list is empty hence there is no -1 index or last element in the list. - Atharva Gundawar
Have you tried to print by console twint.output.users_list ? - Carmoreno
@Carmoreno I still get the same error doing that. - Lyon-Dalipsy
@AtharvaGundawar But isn't the code supposed to iterate over tweets to create that list? Where is the logic error in the code? - Lyon-Dalipsy