Python 3.x Twitter Api的时间延迟问题
我有一个twitter帐户的dataframe,我试图调用一个光度计()来获取详细信息,下面是示例数据和代码Python 3.x Twitter Api的时间延迟问题,python-3.x,pandas,twitter,Python 3.x,Pandas,Twitter,我有一个twitter帐户的dataframe,我试图调用一个光度计()来获取详细信息,下面是示例数据和代码 authors,count generate_output,6 dismisstrump,6 luciano_ocasio,6 Jenny72166737,5 Hong18249170,5 anas_erindra,5 JayChance12,5 viralvm69,5 89nuncamais,5 ngaruman,4 sixyelcastaneda,4 Debisriprasad,4
authors,count
generate_output,6
dismisstrump,6
luciano_ocasio,6
Jenny72166737,5
Hong18249170,5
anas_erindra,5
JayChance12,5
viralvm69,5
89nuncamais,5
ngaruman,4
sixyelcastaneda,4
Debisriprasad,4
import pandas as pd
import botometer
import nltk
from datetime import datetime
import tweepy
import time
author_details=[]
for i, row in df.iterrows():
try:
print(i)
start = datetime.now()
a_name='@'+row['authors']
result = bom.check_account(a_name)
a_details=(a_name, result)
a_details=dict([(a_name, result)])
author_details.append(a_details)
now = datetime.now()
d_time = (now - start).total_seconds()
if int(d_time) < 900 and i<180:
pass
else:
time.sleep(100)
except Exception as e:
print(e)
continue
任何应用延时并将结果存储为单独列的建议您可以尝试此代码,它将捕获异常并等待600秒,您可以将botometer的结果存储为列表。您可以使用结果['scores']['english']直接存储机器人分数
err="429 Client Error: Too Many Requests for url: https://osome-
botometer.p.rapidapi.com/2/check_account"
df['details']=''
df['bot_score']=''
for i, row in df.iterrows():
try:
start = datetime.now()
a_name='@'+row['authors']
result = bom.check_account(a_name)
df.at[i,'det']=[result]
df.at[i,'bot_score'] = int((result['scores']['english'])*100)
except Exception as e:
if e==err:
time.sleep(600)
continue
err="429 Client Error: Too Many Requests for url: https://osome-
botometer.p.rapidapi.com/2/check_account"
df['details']=''
df['bot_score']=''
for i, row in df.iterrows():
try:
start = datetime.now()
a_name='@'+row['authors']
result = bom.check_account(a_name)
df.at[i,'det']=[result]
df.at[i,'bot_score'] = int((result['scores']['english'])*100)
except Exception as e:
if e==err:
time.sleep(600)
continue