Skip to content

Instantly share code, notes, and snippets.

@jkap
Last active November 8, 2018 02:15
Show Gist options
  • Save jkap/5068756 to your computer and use it in GitHub Desktop.
Save jkap/5068756 to your computer and use it in GitHub Desktop.
A quick script I wrote to help pick a winner for a friend's tumblr giveaway
require 'tumblr_client'
Tumblr.configure do |config|
config.consumer_key = "conumer_key"
config.consumer_secret = "consumer_secret"
config.oauth_token = "oauth_token"
config.oauth_token_secret = "oauth_token_secret"
end
client = Tumblr::Client.new
posts = client.posts("blog", id: id, notes_info: true)
notes = posts["posts"].first["notes"]
notes = notes.uniq { |note| note["blog_name"] } # prevent multiple entries
notes = notes.delete_if do |note|
note["blog_name"] == "authors blog" || # prevent author from winning
note["type"] != "reblog" # allow only reblogs to win
end
winner = notes.shuffle.first
puts "#{winner["blog_name"]} - #{winner["type"]}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment