提高Twython Twitter API直接消息发送速度

2024-09-30 18:15:13 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用Twython编写一段python代码,它的目的是在我启动后尽快发送DM。然而,使用我目前的方法,目前只需要5秒左右的时间发送10个直接消息在同一时间。在

我的代码如下:

from twython import Twython
APP_KEY = "xxxxxxx"
APP_SECRET = "xxxxxxx"

OAUTH_TOKENEJOR = 'xxxxx'
OAUTH_TOKEN_SECRETEJOR = 'xxxxx'
OAUTH_TOKENAUSTIN = 'xxxxxxx'
OAUTH_TOKEN_SECRETAUSTIN = 'xxxxxxxxx'
OAUTH_TOKENSTEPH = 'xxxxxxx'
OAUTH_TOKEN_SECRETSTEPH = 'xxxxxxx'
OAUTH_TOKENFRANCO = 'xxxxxxx'
OAUTH_TOKEN_SECRETFRANCO = 'xxxxxxxx'
OAUTH_TOKENDUY = 'xxxxxxxx'
OAUTH_TOKEN_SECRETDUY = 'xxxxxxxxxx'
OAUTH_TOKENQUY = 'xxxxxxxxxx'
OAUTH_TOKEN_SECRETQUY = 'xxxxxxxxxxx'
startTime = datetime.now()

twitteraustin = Twython(APP_KEY, APP_SECRET, OAUTH_TOKENAUSTIN, OAUTH_TOKEN_SECRETAUSTIN)
twitterfranco = Twython(APP_KEY, APP_SECRET, OAUTH_TOKENFRANCO, OAUTH_TOKEN_SECRETFRANCO)
twittersteph = Twython(APP_KEY, APP_SECRET, OAUTH_TOKENSTEPH, OAUTH_TOKEN_SECRETSTEPH)
twitterejor = Twython(APP_KEY, APP_SECRET, OAUTH_TOKENEJOR, OAUTH_TOKEN_SECRETEJOR)
twitterduy = Twython(APP_KEY, APP_SECRET, OAUTH_TOKENDUY, OAUTH_TOKEN_SECRETDUY)
twitterquy = Twython(APP_KEY, APP_SECRET, OAUTH_TOKENQUY, OAUTH_TOKEN_SECRETQUY)


twitterfranco.send_direct_message(screen_name="vphuoc", text= ' hello! ')
twitterfranco.send_direct_message(screen_name="vphuoc", text= ' hello!')
twitteraustin.send_direct_message(screen_name="vphuoc", text= ' hello!')
twitteraustin.send_direct_message(screen_name="vphuoc", text= ' hello!')
twittersteph.send_direct_message(screen_name="vphuoc", text= ' hi!')
twittersteph.send_direct_message(screen_name="vphuoc", text= ' hello!')
twitterejor.send_direct_message(screen_name="vphuoc", text= ' hello!')
twitterejor.send_direct_message(screen_name="vphuoc", text= ' hello!')
twitterduy.send_direct_message(screen_name="vphuoc", text= ' hello!')
twitterduy.send_direct_message(screen_name="vphuoc", text= ' hello!')
twitterquy.send_direct_message(screen_name="vphuoc", text= ' hello!')
twitterquy.send_direct_message(screen_name="vphuoc", text= ' hello!')

print ("DM SENT IN")
print (datetime.now()-startTime)

我有一个相当快的互联网连接(80mps下/上),所以我想知道是否有任何方法可以让我的代码格式不同于以使发送DM的速度更快

谢谢你!在


Tags: keytextnametokensendappmessagehello