Skip to main content

Mike Kreuzer

Twitter followers, Ruby redux

July 28, 2017

Today I'm briefly revisiting January's Elixir code, and rewriting that in Ruby.

Apart from dealing with rate limits, being just the one file & easier to read, the Ruby version runs from the command line and doesn't shower me with dependency build warnings…

It's a small update of the original, original Ruby version of this, to deal with the newer cursored lists that are returned by the twitter API, and uses the Twitter gem.

require 'twitter'

client = Twitter::REST::Client.new do |c|
  c.consumer_key        = 'yep'
  c.consumer_secret     = 'yep'
  c.access_token        = 'yep'
  c.access_token_secret = 'yep'
end

def get_array(method)
  cursored_list_of_ids = method
  begin
    cursored_list_of_ids.to_a
  rescue Twitter::Error::TooManyRequests => error
    puts "Rate limited for: #{error.rate_limit.reset_in / 60} minutes"
    sleep error.rate_limit.reset_in + 1
    retry
  end
end

guilty_ids = get_array(client.friend_ids) - get_array(client.follower_ids)

if guilty_ids.empty?
  puts 'Already square'
else
  puts 'Unfollowed:'
  results = client.unfollow guilty_ids
  results.each { |user| puts "#{user.name} (#{user.screen_name})" }
end

That's the whole thing. Just add in your Twitter credentials and you're good to go, "unfollowing back" to your heart's content.

Tags:

Fifty something days of code

June 28, 2017

Well that didn't work. I never did get around to finishing my 100 days of code.

I'm not unhappy with the progress I did make, and I intend to finish working on Zine, and also still have another new open source project in my sights for the immediate future.

The last few months were taken up by some paid work, and, well, a guy's got to eat. I did play around with what would have been an open source Swift project, but I abandoned it for reasons unrelated to Swift. I got enamoured with Mastodon - a Twitter competitor. Turns out though that while Twitter has a bunch of problems, Mastodon doesn't solve most of them, while adding quite a few of its own. It's not for me, I'm sticking with "the bird site".

Here, normal services will resume momentarily.

Tags:

Built with Zine

February 19, 2017

Pay dirt: with this post I've pushed Zine into production use today, this blog now proudly carries a 'Built with Zine' tag.

Zine is the Ruby static site generator I kicked off my attempt at the 100 days of Code challenge with, and while on Day 27 there are still a whole lot of things to do & to fix – not least of which is writing some damn tests – despite all of that, the engine I'm using now doesn't have any tests either, so… it's time.

A little shy of two weeks on from my last blog post, the major changes to Zine involve adding file watching and incremental builds, and automating the resulting file uploads. Previously I'd rebuilt the whole blog each time, then manually uploaded the files I knew would have changed via Coda or Transmit. RSS, Sass, a tag pages index, and a bunch of other features were added too, but incremental builds & automated uploads are going to be big timesavers for me.

The Ruby gem & Github repo are up to date, and you can follow my progress here on the blog, as well as read my daily progress log & tweets.

Previously

Earlier posts...