My New Approach To Twitter

After a successful experiment with Social Media Abstinence, I knew I wasn’t going to return to Facebook and Twitter, but how could I solve the problems caused by not being on them?

Problem 1: My Twitter Feed isn’t Me Anymore

Having joined in October of 2007, my Twitter feed was about as random as, well, everyone else’s Twitter feed at the time. I live blogged mundane events, shared pictures of food I was about to eat (it was before the specialized food picture service Instagram was launched, ok?), and so forth. Eventually I mixed in the occasional, “Hey, I thought about something and wrote about it on my blog!”

Even the majority of those posts are still dated, but I digress.

Solution 1: Nuke Twitter

I’m not really a “go half way” sort of person, so my solution to old tweets was to just nuke ‘em. It’s actually really easy to do. First, download your feed for historical reasons, you never know when you might be asked what you had for lunch on October 13th, 2008, so it’s good to be prepared.

Then, setup a Twitter App that has a bunch of credentials and stuff. I’m going to assume you can Google your way through this step or already have one.

Finally, nuke everything:

#!/usr/bin/env ruby
require 'rubygems'
require 'twitter'

USERNAME = 'your-name-here'.freeze

class TwitterFeed
  def initialize
    @client = Twitter::REST::Client.new do |config|
      config.consumer_key = ENV['TWITTER_CONSUMER_KEY']
      config.consumer_secret = ENV['TWITTER_CONSUMER_SECRET']
      config.access_token = ENV['TWITTER_OAUTH_TOKEN']
      config.access_token_secret = ENV['TWITTER_OAUTH_SECRET']
    end
  end

  def nuke_tweets
    raw_tweets.each do |t|
      destroy_tweet(t)
    end
  end

  def unfavorite_everything
    favorites = @client.favorites(count: 400)
    @client.unfavorite(favorites)
  end

  private

  def destroy_tweet(tweet_id)
    @client.destroy_status(tweet_id)
  end

  def raw_tweets
    options = { count: 400, include_rts: true }
    @client.user_timeline(ENV['TWITTER_USERNAME'], options)
  end
end

twitter_feed = TwitterFeed.new
twitter_feed.nuke_tweets
twitter_feed.unfavorite_everything

For the last couple of months while I was still using Twitter, I had this script run every time I opened a new terminal window as the method to implement self-destructing tweets (add a tweet age check). That made me feel a bit better but led to an impermanence of the things that actually mattered.

Problem 2: What about the stuff I want to share?

As I mentioned in that social media post, there are a few things that I truly care about and feel comfortable sharing, after the requisite time of thoughtfulness. These are the longer form posts captured on my blog that encompass everything from my Science Fiction writing to things I’ve learned technically that I like to record for my future self.

Since I embrace the Perl programmer virtue of Laziness, I decided to setup my blog to auto-post to Twitter. Since I also embrace the Perl programmer virtue of Hubris, I decided to implement it myself instead of using IFTTT or something like that (not to mention I regularly type the wrong number of t’s).

Solution 2: Synchronize Twitter with Specialized Blog Feed

First I made a Jekyll tag for every post that I wanted to be on Twitter. To be sane, I only went through the last couple months of what I considered the greatest hits, or at least representative of what I’ve been thinking about.

Then I ran this script when I thought people would be sleeping (a few were still awake!) and eighteen posts were created on Twitter in quick succession, effectively catching up my Twitter to my new posting policy.

#!/usr/bin/env ruby
require 'rubygems'
require 'twitter'
require 'feedjira'
require 'ostruct'

class BlogFeed
  BLOG_URL = 'http://www.zhubert.com/twitter.xml'.freeze

  def initialize
    @feed = Feedjira::Feed.fetch_and_parse(BLOG_URL)
  end

  def entries
    entries = {}
    @feed.entries.reverse.each do |entry|
      entries[entry.title] = entry.url
    end
    entries
  end
end

class ParsedTweet < OpenStruct; end

class TwitterFeed
  def initialize
    @client = Twitter::REST::Client.new do |config|
      config.consumer_key = ENV['TWITTER_CONSUMER_KEY']
      config.consumer_secret = ENV['TWITTER_CONSUMER_SECRET']
      config.access_token = ENV['TWITTER_OAUTH_TOKEN']
      config.access_token_secret = ENV['TWITTER_OAUTH_SECRET']
    end
  end

  def tweets
    raw_tweets.map do |t|
      scanned_text = t.text.scan(/\"(.*?)\"/)
      if !scanned_text.empty?
        ParsedTweet.new(title: scanned_text[0][0], id: t.id, text: t.text)
      else
        ParsedTweet.new(id: t.id, text: t.text)
      end
    end
  end

  def destroy_tweet(tweet_id)
    @client.destroy_status(tweet_id)
  end

  def tweet(tweet)
    @client.update(tweet)
  end

  private

  def raw_tweets
    options = { count: 400, include_rts: true }
    @client.user_timeline(ENV['TWITTER_USERNAME'], options)
  end
end

@twitter_feed = TwitterFeed.new
@entries = BlogFeed.new.entries

@twitter_feed.tweets.each do |t|
  next unless t.title
  if @entries.keys.include?(t.title)
    puts "Tweet already exists for: #{t.text}"
    @entries.delete(t.title)
  end
end

@entries.each do |k, v|
  new_tweet = "New post: \"#{k}\" #{v}"
  @twitter_feed.tweet(new_tweet)
  puts "Tweeting: #{new_tweet}"
end

This is a pretty simple ruby script that makes sure everything in the twitter.xml feed from my blog makes it on to Twitter, eventually. The actual variation I run has other jots and tittles, but you get the idea.

Published under personal, twitter

Related Posts

One of the benefits of working for an awesome company like Planning Center is every five years you get to take a whole month off, in addition to your other paid vacation. How fantastic is that?!

Recently I described my experience in taking a whole month off of work and the entire process that went into making that a “success” (by the definition I had established for it). Rather than clog that post with a massive digression, allow me to expound on the “experiment” I mentioned there.