-
-
Save lizconlan/a30f7f0c528f8398ccfd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# untested, might not even work! | |
# | |
# with apologies to @edent - https://twitter.com/edent/status/410910285244153856 | |
require 'json' | |
require 'yaml' | |
require 'twitter' | |
class InsomniacRandom | |
attr_accessor :yaml_file | |
def init(minimum=111111111) | |
@magic_number = minimum | |
@seed = random_number(@magic_number, @magic_number, 499999999999999999) | |
@twitter_client = twitter_init() | |
@yaml_file = "./twitter.yml" | |
end | |
def generate | |
random_id = random_number(@seed, @magic_number, 499999999999999999)) | |
text = get_tweet_text(random_id) | |
text.hash | |
end | |
private | |
def twitter_init | |
conf = YAML.load_file(@yaml_file) | |
Twitter::REST::Client.new do |config| | |
config.consumer_key = conf[:consumer_key] | |
config.consumer_secret = conf[:consumer_secret] | |
config.access_token = conf[:access_token] | |
config.access_token_secret = conf[:access_token_secret] | |
end | |
end | |
def random_number(seed, lower_bound, upper_bound) | |
prng = Random.new(seed) | |
prng.rand(lower_bound...upper_bound) | |
end | |
def get_tweet_text(tweet_id) | |
tweet = @twitter_client.status(tweet_id) # e.g. => 410910285244153856 | |
# should retry on status not available fail? | |
tweet["text"] # e.g. => "Insomniac idea for a RNG. Generate number, look up tweet with that Status ID, hash the output." | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment