Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

return actual tweets in tweepy?

I was writing a twitter program using tweepy. When I run this code, it prints the Python ... values for them, like

<tweepy.models.Status object at 0x95ff8cc>

Which is not good. How do I get the actual tweet?

import tweepy, tweepy.api
key = XXXXX
sec = XXXXX

tok  = XXXXX
tsec = XXXXX

auth = tweepy.OAuthHandler(key, sec)
auth.set_access_token(tok, tsec)
api = tweepy.API(auth)

pub = api.home_timeline()
for i in pub:
        print str(i)
like image 505
tekknolagi Avatar asked Oct 10 '11 14:10

tekknolagi


1 Answers

In general, you can use the dir() builtin in Python to inspect an object.

It would seem the Tweepy documentation is very lacking here, but I would imagine the Status objects mirror the structure of Twitter's REST status format, see (for example) https://dev.twitter.com/docs/api/1/get/statuses/home_timeline

So -- try

print dir(status)

to see what lives in the status object

or just, say,

print status.text
print status.user.screen_name
like image 116
AKX Avatar answered Sep 20 '22 22:09

AKX