我想将 tweepy 对象(用户状态)保存到我的数据库中,输入以下代码后,它只保存具有特定用户名的用户而不是保存所有用户对象。如何让它保存我列表中的所有用户对象?
意见:
consumer_key=""
consumer_secret=""
access_token=""
access_token_secret=""
auth=tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api=tweepy.API(auth)
db=MySQLdb.connect("localhost","","","")
cur=db.cursor()
def tweetstream(request):
statuses=Cursor(api.list_timeline, owner=request.user, slug='Testy').items(20)
for status in statuses:
print "%s\t%s\t%s\t%s" % (status.text,
status.author.screen_name,
status.created_at,
status.source,)
cur.execute("INSERT INTO tweets VALUES (%s, %s, %s, %s)", (status.text,
status.author.screen_name,
status.created_at,
status.source))
return render_to_response('dashboard.html',{'statuses': statuses},context_instance=RequestContext(request))