Пример #1
0
def test_hashtag_object():
    api = TikTokApi()
    assert len(api.getHashtagObject('funny')) > 0


# if __name__ == "__main__":
#     api = TikTokApi()
#     t = api.getTikTokById('6829267836783971589')
#     print(t)
#     print(len(t))
Пример #2
0
    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
Пример #3
0
    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
Пример #4
0
    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()
Пример #5
0
def test_user():
    api = TikTokApi()

    assert api.getUser(
        'charlidamelio')['userInfo']['user']['uniqueId'] == 'charlidamelio'
    sleep(1)
    assert api.getUserObject('charlidamelio')['uniqueId'] == 'charlidamelio'
    sleep(1)
    assert abs(
        len(
            api.userPosts(
                userID="5058536",
                secUID=
                "MS4wLjABAAAAoRsCq3Yj6BtSKBCQ4rf3WQYxIaxe5VetwJfYzW_U5K8",
                count=5)) - 5) <= 1
    sleep(1)
    assert abs(
        len(
            api.userPosts(
                userID="5058536",
                secUID=
                "MS4wLjABAAAAoRsCq3Yj6BtSKBCQ4rf3WQYxIaxe5VetwJfYzW_U5K8",
                count=10)) - 10) <= 1
    sleep(1)
    assert abs(
        len(
            api.userPosts(
                userID="5058536",
                secUID=
                "MS4wLjABAAAAoRsCq3Yj6BtSKBCQ4rf3WQYxIaxe5VetwJfYzW_U5K8",
                count=30)) - 30) <= 1

    # assert len(api.userLikedbyUsername(username="", count=30)) == 30


# api = TikTokApi()
# t = api.getUser('charlidamelio')
# print(t)
# print(t['userInfo']['user'])
Пример #6
0
def test_trending():
    api = TikTokApi()
    assert abs(len(api.bySound('6819262113299565318', 5)) - 5) <= 1
    assert abs(len(api.bySound('6819262113299565318', 10)) - 10) <= 1
    assert abs(len(api.bySound('6819262113299565318', 20)) - 20) <= 1
Пример #7
0
def test_trending():
    api = TikTokApi()
    assert abs(len(api.byUsername('therock', 5)) - 5) <= 2
    assert abs(len(api.byUsername('therock', 10)) - 10) <= 2
    assert abs(len(api.byUsername('therock', 20)) - 20) <= 2
Пример #8
0
from TikTok import TikTokApi
# from TikTokApi import TikTokApi


def test_trending():
    api = TikTokApi()
    assert abs(len(api.byUsername('therock', 5)) - 5) <= 2
    assert abs(len(api.byUsername('therock', 10)) - 10) <= 2
    assert abs(len(api.byUsername('therock', 20)) - 20) <= 2


if __name__ == "__main__":
    api = TikTokApi()
    t = api.byUsername('therock', 5)
    print(t)
    # test_trending()
Пример #9
0
def test_suggested():
    api = TikTokApi()
    assert len(api.getSuggestedHashtagsbyID()) > 0
    assert len(api.getSuggestedMusicbyID()) > 0
    assert len(api.getSuggestedUsersbyID()) > 0
Пример #10
0
def test_suggested_crawlers():
    api = TikTokApi()
    assert len(api.getSuggestedUsersbyIDCrawler(count=50)) == 50
    assert len(api.getSuggestedHashtagsbyIDCrawler(count=10)) > 0
    assert len(api.getSuggestedMusicIDCrawler(count=10)) > 0
Пример #11
0
from datetime import datetime
from TikTok 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 = '******'

# 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
# %%
from time import sleep
from TikTok import TikTokApi
import autoJ as aj
from pandas import DataFrame

api = TikTokApi(debug=True)
# d = api.discoverMusic()
# print(d)

# %%
# print(u)
# print(u.keys())
# udf = DataFrame([u['userInfo']['user']])
# print(udf)

# for i in u['userInfo']['user']:
#     print(i, u['userInfo']['user'][i])
# sleep(2)

# %%
# users = api.getSuggestedUsersbyIDCrawler(count=4, startingId='6880621118412653573', language='en', proxy=None)
# print(users)
# for i in users:
#     print(i)
# %%
# t = api.trending()
# # print(t)
# ta = aj.parse_json(t)
# print(ta.df)
Пример #13
0
def test_trending():
    api = TikTokApi()
    assert abs(len(api.trending(5)) - 5) <= 2
    assert abs(len(api.trending(10)) - 10) <= 2
    assert abs(len(api.trending(20)) - 20) <= 2
Пример #14
0
def test_non_latin1():
    api = TikTokApi()

    assert len(api.byHashtag('селфи', count=3)) == 3

    
Пример #15
0
def test_hashtag():
    api = TikTokApi()
    assert abs(len(api.byHashtag('funny', 5))-5) <= 1
    assert abs(len(api.byHashtag('funny', 10))-10) <= 1
    assert abs(len(api.byHashtag('funny', 20))-20) <= 1
Пример #16
0
def test_user_object():
    api = TikTokApi()
    assert len(api.getUserObject('therock')) > 0
Пример #17
0
def test_music_object():
    api = TikTokApi()
    assert len(api.getMusicObject('6820695018429253633')) > 0
Пример #18
0
def test_search_for():
    api = TikTokApi()
    assert len(api.search_for_hashtags('a')) >= 20
    assert len(api.search_for_music('a')) >= 20
    assert len(api.search_for_users('a')) >= 20
Пример #19
0
def test_tiktok_object():
    api = TikTokApi()
    assert len(api.getTikTokById('6829267836783971589')) > 0
    assert len(
        api.getTikTokByUrl(
            "https://www.tiktok.com/@therock/video/6829267836783971589")) > 0
Пример #20
0
def test_trending():
    api = TikTokApi()
    assert len(api.discoverHashtags()) > 0
    assert len(api.discoverMusic()) > 0