-
-
Notifications
You must be signed in to change notification settings - Fork 1k
/
Copy pathdemo_user_pager.py
49 lines (32 loc) · 1.32 KB
/
demo_user_pager.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from datetime import datetime
from TikTokApi import TikTokApi
api = TikTokApi(debug=True)
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 = "therock"
# count and list all of the posts for a given user with the pager
total = 0
pager = api.get_user_pager(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.get_user_object(username)
page = api.user_page(user["id"], user["secUid"], page_size=30, after=APR_24)
printPage(page["items"])
new_posts = len(page["items"])
print("{} has {} posts after {}".format(username, new_posts, APR_24))
# Count and list all of the posts before a certain date for a given user with the pager
total = 0
pager = api.get_user_pager(username, page_size=count, before=APR_24)
for page in pager:
printPage(page)
total += len(page)
print("{} has {} posts from before {}".format(username, total, APR_24))
print("Should be {}".format(all_posts - new_posts))