Skip to content

Instantly share code, notes, and snippets.

@Roach
Created August 23, 2015 20:06
Show Gist options
  • Save Roach/d129863163fcbc3e43c2 to your computer and use it in GitHub Desktop.
Save Roach/d129863163fcbc3e43c2 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'json'
require 'htmlentities'
require 'twitter'
sets = %w(
Base
CAHe1
CAHe2
CAHe3
)
# CAH Cards JSON
# https://github.com/nodanaonlyzuul/against-humanity/blob/master/source/cards.json
cards = JSON.parse(File.read("cards.json")).select{ |card| sets.include?(card["expansion"]) }
@questions, @answers = cards.partition{ |card| card["cardType"] == "Q" }
twitter = Twitter::REST::Client.new do |config|
config.consumer_key = "XXX"
config.consumer_secret = "XXX"
config.access_token = "XXX"
config.access_token_secret = "XXX"
end
def generate_answer
black_card_data = @questions.sample
black_card = black_card_data["text"].gsub('_', '%s')
white_cards = @answers.sample(black_card_data["numAnswers"]).map{ |card| card["text"].gsub('.', '') }
if black_card.end_with? "?"
"#{black_card.to_str} #{white_cards.join(" ")}"
else
black_card % white_cards
end
end
tweet_text = HTMLEntities.new.decode generate_answer.downcase
if tweet_text.length < 140
twitter.update(tweet_text)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment