wrote a method to download all the raw pastes to a file inside of a directory.

added a --download and -d shorthand switch to download the raw paste files from a public scrape.
i need to check to make sure that it is the correct way to do it, and also check to see if a filename exists already.
this will prevent duplicate files from being downloaded.
This commit is contained in:
booboy 2018-11-05 03:15:29 -06:00
parent ebde6ca0f2
commit 4853f92ecd
2 changed files with 20 additions and 4 deletions

1
.gitignore vendored
View file

@ -6,6 +6,7 @@
/pkg/ /pkg/
/spec/reports/ /spec/reports/
/tmp/ /tmp/
/data
Gemfile.lock Gemfile.lock
# rspec failure tracking # rspec failure tracking

View file

@ -6,6 +6,16 @@ require 'optparse'
pb = Pastebinner.new(ENV['pastebin_api_key'], ENV['pastebin_username'], ENV['pastebin_password']) pb = Pastebinner.new(ENV['pastebin_api_key'], ENV['pastebin_username'], ENV['pastebin_password'])
api_dev_key = ENV['pastebin_api_key'] api_dev_key = ENV['pastebin_api_key']
# 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)
keys.map do |id|
File.write("../data/pastebin_paste_key_#{id[:key]}", pb.raw_paste_data(id[:key]))
end
end
opts = {} opts = {}
OptionParser.new do |parser| OptionParser.new do |parser|
@ -27,6 +37,9 @@ OptionParser.new do |parser|
parser.on('-gk', '--get_keys', "Get unique paste keys from public pastes") do |gk| parser.on('-gk', '--get_keys', "Get unique paste keys from public pastes") do |gk|
opts[:gk] = true opts[:gk] = true
end end
parser.on('-d', '--download', 'Download all public pastes to data directory.') do |d|
opts[:d] = true
end
parser.on('-t', '--trending', 'Trending pastes.') do |t| parser.on('-t', '--trending', 'Trending pastes.') do |t|
opts[:t] = true opts[:t] = true
end end
@ -43,9 +56,11 @@ elsif opts[:t]
elsif opts[:gk] elsif opts[:gk]
r = pb.scrape_public_pastes r = pb.scrape_public_pastes
puts pb.get_unique_paste_keys(r) puts pb.get_unique_paste_keys(r)
else elsif opts[:d]
puts "Downloading paste data into the data directory..."
download_pastes(pb)
puts "Complete."
else opts = false
puts 'please provide arguments' puts 'please provide arguments'
exit
end end
#pp = pb.scrape_public_pastes
#puts pb.get_unique_paste_keys(pp)