Skip to content

Instantly share code, notes, and snippets.

@heffo42
Last active July 7, 2019 19:06
Show Gist options
  • Save heffo42/f6f8b5495b7a42832ab05ef3a1deb04b to your computer and use it in GitHub Desktop.
Save heffo42/f6f8b5495b7a42832ab05ef3a1deb04b to your computer and use it in GitHub Desktop.
#tweets is the html data as a bs4 (beautifulsoup) object
def writeTweets(tweets):
newTweetRecords = []
for tweet in tweets:
try:
if tweet.find("a", {"class" : "js-action-profile-promoted"}):
continue
text = tweet.find("p", {"class" : "tweet-text"}).get_text()
date = tweet.find("span", {"class" : "_timestamp"})["data-time-ms"]
tweetId = tweet['data-item-id']
tweetRecord = {"text" : text, "date" : date, "tweetId" : tweetId}
newTweetRecords.append(tweetRecord)
except:
print("Unable to process tweet")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment