Last active
November 8, 2018 02:15
-
-
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
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
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