mail@pastecode.io avatar
2 years ago
1.3 kB
# Import the `TikTokAPI` class from the `tiktok-api` library
from tiktok_api import TikTokAPI

# Authenticate your app with the TikTok API
api = TikTokAPI(client_id='your-client-id', client_secret='your-client-secret')

# Use the `api` object to access the TikTok API and perform various operations
# For example, you can use it to search for videos, users, or hashtags, or to get information about videos

# First, search for popular videos on TikTok
videos = api.trending(count=100)

# Iterate over the list of videos and calculate the proportion of women who like each video
# relative to the total number of likes for the video
for video in videos:
  total_likes = video['stats']['like_count']
  female_likes = video['stats']['female_like_count']
  proportion_female_likes = female_likes / total_likes
  # Print the proportion of female likes for each video
  print(video['id'], proportion_female_likes)
# Sort the videos by the proportion of female likes, in descending order
sorted_videos = sorted(videos, key=lambda x: x['stats']['female_like_count'] / x['stats']['like_count'], reverse=True)

# Print the sorted list of videos
for video in sorted_videos:
  print(video['id'], video['stats']['female_like_count'] / video['stats']['like_count'])