def test_page_size(self):
        """Pages should be pretty close to the specified size"""
        api = TikTokApi()

        pager = api.getUserPager('therock', page_size=5)

        page = pager.__next__()
        assert abs(len(page) - 5) <= 2

        page = pager.__next__()
        assert abs(len(page) - 5) <= 2
    def test_user_pager_before(self):
        """Should always request therock's first 19 tiktoks across 2 pages"""
        APR_24 = 1587757436000  # 2020-04-24 15:43:56 to be precise. Must be ms-precision timestamp

        api = TikTokApi()
        pager = api.getUserPager('therock', page_size=10, before=APR_24)

        total_tts = 0
        pages = 0
        for page in pager:
            pages += 1
            total_tts += len(page)

        assert pages == 2
        assert total_tts == 19
    def test_user_pager_before_after(self):
        """Should always request the 7 tiktoks between those times"""
        APR_24 = 1587757437000  # 2020-04-24 15:43:57
        AUG_10 = 1597076218000  # 2020-08-10 12:16:58

        api = TikTokApi()
        pager = api.getUserPager('therock',
                                 page_size=3,
                                 after=APR_24,
                                 before=AUG_10)

        total_tts = 0
        pages = 0
        for page in pager:
            pages += 1
            total_tts += len(page)

        assert pages == 3
        assert total_tts == 7


# t = TestUserPager()
Exemple #4
0

def printPage(page):
    """Just prints out each post with timestamp and description"""
    for post in page:
        print("{}: {}".format(datetime.fromtimestamp(post['createTime']),
                              post['desc']))


count = 20
username = '******'

# count and list all of the posts for a given user with the pager
total = 0

pager = api.getUserPager(username, page_size=count)

for page in pager:
    printPage(page)
    total += len(page)

print('{} has {} posts'.format(username, total))
all_posts = total

# List all of the posts for a given user after a certain date

APR_24 = 1587757438000  # 2020-04-24 15:43:58 to be precise. Must be ms-precision UNIX timestamp
user = api.getUserObject(username)
page = api.userPage(user['id'], user['secUid'], page_size=30, after=APR_24)

printPage(page['items'])