Russell-Newton / TikTokPy

Extract data from TikTok without needing any login information or API keys.
https://pypi.org/project/tiktokapipy/
MIT License
203 stars 25 forks source link

[BUG] AttributeError: 'DeferredItemListIterator' object has no attribute 'sorted_by' #56

Closed paweenwat-man closed 1 year ago

paweenwat-man commented 1 year ago

To Reproduce

    with TikTokAPI() as api:
        utc = pytz.UTC
        challenge = api.challenge(tag_name)
        videos = takewhile(lambda video: video.create_time > utc.localize(SINCE_DATE), 
            dropwhile(lambda video: video.create_time > utc.localize(UNTIL_DATE), 
                challenge.videos.sorted_by(key=lambda video: video.create_time, reverse=True)))

Expected behavior a sorted iterator of TikTok videos

Version Information pydantic==2.0.3 pydantic_core==2.3.0 playwright==1.36.0 tiktokapipy==0.2.0.post2

System Information OS: Windows 11 on desktop computer

Region Information Thailand

Russell-Newton commented 1 year ago

This feature was removed in version 0.2.0. If I forgot to remove it from the documentation, then I'll have to remove it. TikTok supplies videos under a certain tag according to its algorithm, so there's no direct way to get the video list sorted by create time. The removed solution just sorted a fixed number of grabbed videos. To get the same effect you can use:

sorted(challenge.videos, key=...)

to collect all of the videos tagged with a challenge and sort them (this is a bad idea).

Or you can use:

sorted(challenge.videos.limit(20), key=...)

to collect the first 20 videos and sort them. This number can obviously be changed just by changing the limit parameter.