Last active
August 29, 2015 13:56
-
-
Save dmerrick/9261730 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/usr/bin/env ruby | |
require 'rubygems' | |
require 'json' | |
require 'open-uri' | |
require 'slack-notifier' | |
# use the turtle subreddit | |
turtles = "http://www.reddit.com/r/turtle.json" | |
json = JSON.load(open(turtles)) | |
# select all imgur links that are not self posts | |
image_links = json["data"]["children"] | |
image_links.reject! { |post| post["data"]["is_self"] } | |
image_links.select! { |post| post["data"]["url"] =~ /imgur/ } | |
# select a random post | |
link = image_links.sample["data"]["url"] | |
# add .jpg to the end if needed | |
if File.basename(URI.parse(link).path) !~ /\.(gif|jpg|png)/ | |
link += '.jpg' | |
end | |
# post to slack | |
notifier = Slack::Notifier.new "zencoder", ARGV.shift | |
status = notifier.ping link, channel: ARGV.shift || '#random' | |
# print the status | |
puts "#{status}: #{link}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment