tekknolagi tekknolagi - 8 months ago 65
Python Question

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)


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