-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathuser.py
More file actions
30 lines (24 loc) · 1 KB
/
user.py
File metadata and controls
30 lines (24 loc) · 1 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
import os
import urllib.request
from pathlib import Path
from urllib.parse import urlparse
import login as login
from twitter_openapi_python import TwitterOpenapiPython
cookies_dict = login.login().get_cookies().get_dict()
𝕏 = TwitterOpenapiPython().get_client_from_cookies(cookies=cookies_dict)
screen_name = "elonmusk"
user_response = 𝕏.get_user_api().get_user_by_screen_name(
screen_name=screen_name,
)
print(f"rate_limit_remaining: {user_response.header.rate_limit_remaining}")
elonmusk = user_response.data.user
print(f"screen_name: {elonmusk.legacy.screen_name}")
print(f"friends_count: {elonmusk.legacy.friends_count}")
print(f"followers_count: {elonmusk.legacy.followers_count}")
os.makedirs("media", exist_ok=True)
url = urlparse(elonmusk.legacy.profile_image_url_https)
ext = os.path.splitext(url.path)[1]
data = urllib.request.urlopen(elonmusk.legacy.profile_image_url_https).read()
os.makedirs("media", exist_ok=True)
with open(Path("media", screen_name + ext), mode="wb+") as f:
f.write(data)