Skip to content

Instantly share code, notes, and snippets.

@febriliankr
Last active April 8, 2021 09:24
Show Gist options
  • Save febriliankr/9ea6464e60d58b4af715b52aa3cdc4d1 to your computer and use it in GitHub Desktop.
Save febriliankr/9ea6464e60d58b4af715b52aa3cdc4d1 to your computer and use it in GitHub Desktop.
csvFile = open(search_keyword+'.csv', 'a+', newline='', encoding="utf-8")
csvWriter = csv.writer(csvFile)
created = []
id_twitter = []
username = []
text = []
for tweet in tweepy.Cursor(api.search, q=search_keyword, count=300, lang='id', result_type="latest").items(search_limit):
print(tweet.created_at, tweet.id, tweet.user.name, tweet.text)
created.append(tweet.created_at)
id_twitter.append(tweet.id)
username.append(tweet.user.name)
text.append(tweet.text)
tweets = [tweet.created_at, tweet.id,
tweet.user.name, tweet.text]
csvWriter.writerow(tweets)
dictTweets = {"timestamp": created, "id_twitter": id_twitter,
"username": username, "text": text}
dataFrame = pd.DataFrame(dictTweets, columns=[
"timestamp", "id_twitter", "username", "text"])
dataFrame
openFile = open(search_keyword + ".csv", "r")
print(openFile.read())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment