1- <img src =" https://i.imgur.com/iJe6rsZ.png " width =" 500 " >
1+ <img src =" https://i.imgur.com/iJe6rsZ.png " width =" 500 " >
22
33
44
@@ -43,10 +43,6 @@ This library uses scraping and does not require an API key.
4343
4444This library is free to use.
4545
46- ### Both Synchronous and Asynchronous Support
47-
48- Twikit supports both synchronous and asynchronous.
49-
5046
5147## Functionality
5248
@@ -77,6 +73,7 @@ pip install twikit
7773** Define a client and log in to the account.**
7874
7975``` python
76+ import asyncio
8077from twikit import Client
8178
8279USERNAME = ' example_user'
@@ -86,24 +83,27 @@ PASSWORD = 'password0000'
8683# Initialize client
8784client = Client(' en-US' )
8885
89- client.login(
90- auth_info_1 = USERNAME ,
91- auth_info_2 = EMAIL ,
92- password = PASSWORD
93- )
86+ async def main ():
87+ await client.login(
88+ auth_info_1 = USERNAME ,
89+ auth_info_2 = EMAIL ,
90+ password = PASSWORD
91+ )
92+
93+ asyncio.run(main())
9494```
9595
9696** Create a tweet with media attached.**
9797
9898``` python
9999# Upload media files and obtain media_ids
100100media_ids = [
101- client.upload_media(' media1.jpg' ),
102- client.upload_media(' media2.jpg' )
101+ await client.upload_media(' media1.jpg' ),
102+ await client.upload_media(' media2.jpg' )
103103]
104104
105105# Create a tweet with the provided text and attached media
106- client.create_tweet(
106+ await client.create_tweet(
107107 text = ' Example Tweet' ,
108108 media_ids = media_ids
109109)
@@ -112,7 +112,7 @@ client.create_tweet(
112112
113113** Search the latest tweets based on a keyword**
114114``` python
115- tweets = client.search_tweet(' python' , ' Latest' )
115+ tweets = await client.search_tweet(' python' , ' Latest' )
116116
117117for tweet in tweets:
118118 print (
@@ -124,7 +124,7 @@ for tweet in tweets:
124124
125125** Retrieve user tweets**
126126``` python
127- tweets = client.get_user_tweets(' 123456' , ' Tweet' )
127+ tweets = await client.get_user_tweets(' 123456' , ' Tweet' )
128128
129129for tweet in tweets:
130130 print (tweet.text)
0 commit comments