Skip to content

Instantly share code, notes, and snippets.

@alexbowe
Last active May 17, 2017 12:12
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexbowe/10624449 to your computer and use it in GitHub Desktop.
Save alexbowe/10624449 to your computer and use it in GitHub Desktop.
Find the Nth Tweet from your Twitter archive .csv file
# To run, from shell type: python tweet_finder.py
# Must be run in the same directory as the downloaded csv file.
import csv
# Modify this number if you want a different nth Tweet
# Should be 1-based (i.e. first tweet is the 1th, not 0th)
num = 40000
# Change the path if you want to run it from a different directory
path = "tweets.csv"
with open(path, "r") as f:
# [1:] to remove the header
tweets = list(csv.reader(f))[1:]
if len(tweets) < num:
print "There are less than %d tweets." % (num)
else:
# Archive Format: Reverse chronological order. Last field is Tweet content.
print tweets[-num][-1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment