Skip to content

Instantly share code, notes, and snippets.

@blakejakopovic
Created April 18, 2014 01:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blakejakopovic/11019703 to your computer and use it in GitHub Desktop.
Save blakejakopovic/11019703 to your computer and use it in GitHub Desktop.
read_reddit_saved
#!/usr/bin/env ruby
require 'dotenv'
Dotenv.load '~/bin/.env'
require 'snoo'
require 'terminal-notifier'
username = ENV.fetch('REDDIT_USERNAME')
password = ENV.fetch('REDDIT_PASSWORD')
reddit_hostname = "http://reddit.com"
reddit = Snoo::Client.new
reddit.log_in username, password
saved = reddit.get_user_listing(username, type: 'saved')['data']['children']
collection_object = Hash.new {|h,k| h[k] = [] }
collection = saved.each_with_object(collection_object) do |child, h|
h[:links] << reddit_hostname + child['data']['permalink']
h[:ids] << "t3_#{child['data']['id']}"
end
unless collection[:links].empty?
links = collection[:links].reverse
# Open first link in a new window
system "/usr/local/bin/chrome-cli open #{links.shift} -n"
links.map do |link|
system "/usr/local/bin/chrome-cli open #{link}"
end
# system "open #{collection[:links].join(' ')}"
collection[:ids].map {|id| reddit.unsave(id); sleep 1 }
sleep 10
new_saved_count = reddit.get_user_listing(username, type: 'saved')['data']['children'].count
puts "#{new_saved_count} favourite tweets remain"
TerminalNotifier.notify("#{new_saved_count} saves remain", title: "Reddit Saves")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment