48 lines
1.3 KiB
Ruby
Executable file
48 lines
1.3 KiB
Ruby
Executable file
#!/usr/bin/env ruby
|
|
require '../lib/pastebinner'
|
|
require '../lib/pastebinner/option_parser'
|
|
require 'pry'
|
|
|
|
# setup our object and grab a session key
|
|
pb = Pastebinner.new(ENV['pastebin_api_key'], ENV['pastebin_username'], ENV['pastebin_password'])
|
|
|
|
# pass in the Pastebinner.new client.
|
|
# will download all of the raw pastes from the public scrape results into each own file in data dir.
|
|
def download_pastes(pb)
|
|
pub_pastes = pb.scrape_public_pastes
|
|
keys = pb.get_unique_paste_keys(pub_pastes)
|
|
data_dir = '../data/'
|
|
filename = 'pastebin_paste_key'
|
|
binding.pry
|
|
keys.map do |id|
|
|
if File.exist?(data_dir + filename + "_#{id}")
|
|
puts "#{id} already exists on your filesystem, skipping..."
|
|
else
|
|
File.write(data_dir + filename + "_#{id}", pb.raw_paste_data(id))
|
|
end
|
|
end
|
|
end
|
|
|
|
options = OptionParser.parse!
|
|
|
|
if options[:s]
|
|
puts pb.scrape_public_pastes
|
|
elsif options[:r] && options[:k]
|
|
key = options[:k]
|
|
puts pb.raw_paste_data(key)
|
|
elsif options[:t]
|
|
puts pb.list_trending_pastes
|
|
elsif options[:g]
|
|
r = pb.scrape_public_pastes
|
|
puts pb.get_unique_paste_keys(r)
|
|
elsif options[:d]
|
|
puts 'Downloading paste data into the data directory...'
|
|
download_pastes(pb)
|
|
puts 'Complete.'
|
|
elsif options[:k]
|
|
puts '-k or --key= requires -r,--raw'
|
|
exit
|
|
else options = false
|
|
puts 'please provide arguments'
|
|
exit
|
|
end
|