Skip to content

Instantly share code, notes, and snippets.

@djbender
Forked from alyssais/thread.rb
Created March 25, 2018 14:58
Show Gist options
  • Save djbender/b0551ec0cb5f3bfcd9d74bcc337a09fe to your computer and use it in GitHub Desktop.
Save djbender/b0551ec0cb5f3bfcd9d74bcc337a09fe to your computer and use it in GitHub Desktop.
My really hacky livetweeting script. You pass in the ID of the tweet to continue the thread from.
require "yaml"
require "twitter"
config = YAML.load_file(File.expand_path("~/.trc")).dig("profiles", "qyliss").each_value.first
last_status = ARGV.fetch(0)
twitter = Twitter::REST::Client.new do |t|
t.consumer_key = config.fetch("consumer_key")
t.consumer_secret = config.fetch("consumer_secret")
t.access_token = config.fetch("token")
t.access_token_secret = config.fetch("secret")
end
loop do
file = Tempfile.new("tweet")
file.write(" #BathRuby")
file.close
system ENV.fetch("EDITOR"), file.path
text = File.read(file.path)
file.unlink
break unless text[/\S/]
begin
last_status = twitter.update(text, in_reply_to_status_id: last_status).tap { |tweet|
puts tweet.text
puts tweet.id
}.id
rescue
retry
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment