Reputation: 973
I want to be able to run a search for keywords (ContinuousDelivery
in this example) and have it return the date created, text and screen name of tweets containing the keyword and store it into a CSV which will ultimately be ported to a relational database.
I can get the created and text but not the screen name with code below.
I am also wondering how I can be sure I am getting all of the results pursuant to my request.
I have looked at Twitter API documentation and the tweepy
GitHub but neither has got me far.
# --OAuth Headers omitted--
api = tweepy.API(auth)
# Open/Create a file to append data
csvFile = open('result17.csv', 'a')
#Use csv Writer
csvWriter = csv.writer(csvFile)
for tweet in tweepy.Cursor(api.search,
q="ContinuousDelivery",
#since="2014-02-14",
#until="2014-02-15",
lang="en").items(5000000):
#Write a row to the csv file/ I use encode utf-8
csvWriter.writerow([tweet.created_at, tweet.text.encode('utf-8'), tweet.screen_name])
print tweet.created_at, tweet.text, tweet.screen_name
csvFile.close()
Upvotes: 1
Views: 2725
Reputation: 13448
To get the author's screenname use tweet.author.screen_name. The profile is it's own object inside the tweet.
Upvotes: 1