65 lines
2.1 KiB
Ruby
Executable file
65 lines
2.1 KiB
Ruby
Executable file
#!/usr/bin/env ruby
|
|
require 'bundler/setup'
|
|
require 'pastebinner'
|
|
|
|
# setup our object and grab a session key
|
|
pb = Pastebinner::ApiClient.new(ENV['pastebin_api_key'], ENV['pastebin_username'], ENV['pastebin_password'])
|
|
|
|
# set the commandline client to grab 50 pastes by default. this should be an option to config though once we add configuration methods
|
|
paste_max = 50
|
|
|
|
# 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_json(pb, paste_max)
|
|
pub_pastes = pb.scrape_public_pastes(paste_max)
|
|
keys = pb.get_unique_paste_keys(pub_pastes)
|
|
data_dir = '../data/'
|
|
filename = 'pastebin_paste_key'
|
|
keys.map do |id|
|
|
if File.exist?("#{data_dir}#{filename}_#{id}.json")
|
|
puts "#{data_dir}#{filename}_#{id}.json already exists on your filesystem, skipping..."
|
|
else
|
|
File.write("#{data_dir}#{filename}_#{id}.json", pb.json_paste(pb.raw_paste_data(id), pb.raw_paste_metadata(id)))
|
|
end
|
|
end
|
|
end
|
|
|
|
def download_pastes_raw(pb, paste_max)
|
|
pub_pastes = pb.scrape_public_pastes(paste_max)
|
|
keys = pb.get_unique_paste_keys(pub_pastes)
|
|
data_dir = '../data/'
|
|
filename = 'pastebin_paste_key'
|
|
keys.map do |id|
|
|
if File.exist?("#{data_dir}#{filename}_#{id}.raw")
|
|
puts "#{data_dir}#{filename}_#{id}.raw already exists on your filesystem, skipping..."
|
|
else
|
|
File.write("#{data_dir}#{filename}_#{id}.raw", pb.raw_paste_data(id))
|
|
end
|
|
end
|
|
end
|
|
|
|
options = Pastebinner::OptionParser.parse!
|
|
|
|
if options[:s]
|
|
puts pb.scrape_public_pastes(paste_max)
|
|
elsif options[:r] && options[:k]
|
|
key = options[:k]
|
|
puts pb.raw_paste_data(key)
|
|
elsif options[:g]
|
|
r = pb.scrape_public_pastes(paste_max)
|
|
puts pb.get_unique_paste_keys(r)
|
|
elsif options[:j]
|
|
puts 'Downloading paste data as a json into the data directory...'
|
|
download_pastes_json(pb)
|
|
puts 'Complete.'
|
|
elsif options[:d]
|
|
puts 'Downloading paste data into the data directory...'
|
|
download_pastes_raw(pb)
|
|
puts 'Complete.'
|
|
elsif options[:k]
|
|
puts '-k or --key= requires -r,--raw'
|
|
exit
|
|
else options = false
|
|
puts 'please provide arguments'
|
|
exit
|
|
end
|