python - Looking for a more Pythonic way to grab text from individual tweets -
i'm trying grab text of first 50 tweets word/hashtag taken input user. tried writing for-loops this, example:
for in range(1,50): self.status_texts[i] = (statuses[i]) in range(1,50): self.tweets = self.status_texts[i]['text']
but comes keyerror
. i'm looking way combine self.status_texts = (statuses[0])
action , action retrieves text, in return.
is possible? can of give me tips on started?
twitter_api = twitter.twitter(auth=auth) q = input('what search for?') q = str(q) count = 50 search_results = twitter_api.search.tweets(q=q, count=count) statuses = search_results['statuses'] f = open('twitter.txt', 'w') class tweeter(): def puretweets(self): self.status_texts = (statuses[0]) self.status_texts1 = (statuses[1]) self.status_texts2 = (statuses[2]) return self.status_texts['text'], self.status_texts1['text'], self.status_texts2['text']
as far guess, want return tuple tweets text stored in it, can done as:
def puretweets(self): # self.status_texts = (statuses[0]) # self.status_texts1 = (statuses[1]) # self.status_texts2 = (statuses[2]) return (statuses[i] in range(1, 50))
or
def puretweets(self): return statuses[1:50]
Comments
Post a Comment