halcy / Mastodon.py

Python wrapper for the Mastodon ( https://github.com/mastodon/mastodon/ ) API.
MIT License
867 stars 150 forks source link

TypeError on automated pagination #341

Open FedericoCeratto opened 1 year ago

FedericoCeratto commented 1 year ago

Hello and thanks for developing this library.

mastodon.fetch_next called on an empty list of toots leads to:

  File "/usr/lib/python3/dist-packages/mastodon/utility.py", line 206, in fetch_next
    method = params['_pagination_method']
             ~~~~~~^^^^^^^^^^^^^^^^^^^^^^
TypeError: list indices must be integers or slices, not str

Steps to reproduce:

toots = mastodon.timeline()
while True:
    toots = mastodon.fetch_next(toots)

It seems that fetch_next returns an empty list after 800 toots and breaks the next run. Perhaps the library could provide an iterator that terminates at the end instead?

Thanks!

halcy commented 1 year ago

yeah, that sounds like a really good idea, actually.

Workshopping this in my head, so I'm wondering, what do (or others) you think would make more sense:

gglanzani commented 2 weeks ago

Late to the party, but IMHO, option 2 (An iterator that iterates post and fetches next page as needed?) seems better.