Created
June 11, 2014 20:46
-
-
Save rwilcox/a787b9a8a139dcb0f674 to your computer and use it in GitHub Desktop.
show a random AAWWWWWW image in your favorite editor (bbedit)
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
#!/usr/bin/env ruby | |
# FOR MAX EFFECTIVENESS: | |
# Put in ~/(Dropbox or Library)/Application Support/BBEdit/Scripts | |
require 'net/http' | |
require 'json' | |
http = Net::HTTP.new('www.reddit.com') | |
response = http.request(Net::HTTP::Get.new("/r/aww.json")) | |
json = JSON.parse(response.body) | |
if json['data']['children'].count <= 0 | |
#send_event('aww', image: placeholder) | |
our_path = "http://img1.wikia.nocookie.net/__cb20130517022805/witch/images/9/97/Nyantocat.gif" | |
else | |
urls = json['data']['children'].map{|child| child['data']['url'] } | |
# Ensure we're linking directly to an image, not a gallery etc. | |
valid_urls = urls.select{|url| url.downcase.end_with?('png', 'gif', 'jpg', 'jpeg')} | |
our_path = valid_urls.sample(1).first | |
end | |
File.write("/tmp/bb_aww.png", Net::HTTP.get(URI.parse(our_path))) | |
`/usr/bin/osascript -e 'tell application \"BBEdit\" to open POSIX file \"/tmp/bb_aww.png\"'` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment