Skip to content

Instantly share code, notes, and snippets.

@fofr
Last active January 16, 2023 17:34
Show Gist options
  • Save fofr/9169311 to your computer and use it in GitHub Desktop.
Save fofr/9169311 to your computer and use it in GitHub Desktop.
Convert an exported CSV of tweets into a SIFTTTER format
#!/usr/bin/ruby
# Convert an exported CSV of tweets into a SIFTTTER format
# Export from https://twitter.com/settings/account
# SIFTTTER: http://craigeley.com/post/72565974459/sifttter-an-ifttt-to-day-one-logger
require 'time'
require 'erb'
require 'date'
require 'csv'
output_path = 'tweets.md'
input_path = 'tweets.csv'
username = ''
output = ''
entries = []
data = CSV.read(input_path)
class Entry
def parse(tweet)
@tweet_id = tweet[0]
@in_reply_to_status_id = tweet[1]
@in_reply_to_user_id = tweet[2]
@timestamp = tweet[3]
@source = tweet[4].gsub(/<[^>]+>/, '')
@text = tweet[5].gsub(/\n/, '')
@retweeted_status_id = tweet[6]
@retweeted_status_user_id = tweet[7]
@retweeted_status_timestamp = tweet[8]
@expanded_urls = tweet[9]
@date = Time.parse(@timestamp.to_s).strftime('%B %d, %Y at %I:%M%p')
end
def render
"- #{@date} - #{@text} [Twitter](https://twitter.com/#{username}/status/#{@tweet_id}) via #{@source}@done\n"
end
end
data.drop(1).each do |line|
entry = Entry.new
entry.parse(line)
entries << entry
end
fh = File.new(File.expand_path(output_path),'w+')
fh.puts entries.map {|entry| entry.render}
fh.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment