-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathuserinfo.py
More file actions
77 lines (64 loc) · 2.34 KB
/
userinfo.py
File metadata and controls
77 lines (64 loc) · 2.34 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import requests
import tkinter as tk
from io import BytesIO
from urllib.request import urlopen
from json import JSONDecodeError
from rich.console import Console
from rich.table import Table
# Create Tkinter window
window = tk.Tk()
window.geometry("400x400")
# Create header label
header_label = tk.Label(text="TikTok User Info", font=("Arial", 18))
header_label.pack(pady=10)
# Create input label and entry field
input_label = tk.Label(text="Enter TikTok username:")
input_label.pack(pady=10)
input_entry = tk.Entry(width=30)
input_entry.pack()
# Create function to retrieve and display user info
def get_user_info():
# Get username from input field
username = input_entry.get()
# Make request to TikTok API to get user info
url = f"https://www.tiktok.com/node/share/user/@{username}"
try:
response = requests.get(url).json()
except JSONDecodeError:
console = Console()
console.print("Invalid username. Please enter a valid username.")
return
# Extract relevant user info from response
user_info = response['userInfo']
username = user_info['uniqueId']
avatar_url = user_info['avatarThumb']
num_videos = user_info['videoCount']
num_followers = user_info['followerCount']
num_following = user_info['followingCount']
is_private = user_info['isSecret']
is_verified = user_info['verified']
# Create table to display user info
table = Table(show_header=False, show_lines=True)
table.add_column(justify="right")
table.add_column()
table.add_row("Username:", username)
# Download and display user avatar
response = urlopen(avatar_url)
img_data = response.read()
img = tk.PhotoImage(data=img_data)
avatar_label = tk.Label(image=img)
avatar_label.image = img
table.add_row("Avatar:", avatar_label)
table.add_row("Number of videos:", str(num_videos))
table.add_row("Number of followers:", str(num_followers))
table.add_row("Number of following:", str(num_following))
table.add_row("Private account:", "Yes" if is_private else "No")
table.add_row("Verified account:", "Yes" if is_verified else "No")
# Display table
console = Console()
console.print(table)
# Create "Search user" button
search_button = tk.Button(text="Search user", command=get_user_info)
search_button.pack(pady=10)
# Run Tkinter window
window.mainloop()