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:
parent
ebde6ca0f2
commit
4853f92ecd
2 changed files with 20 additions and 4 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -6,6 +6,7 @@
|
|||
/pkg/
|
||||
/spec/reports/
|
||||
/tmp/
|
||||
/data
|
||||
Gemfile.lock
|
||||
|
||||
# rspec failure tracking
|
||||
|
|
|
@ -6,6 +6,16 @@ require 'optparse'
|
|||
pb = Pastebinner.new(ENV['pastebin_api_key'], ENV['pastebin_username'], ENV['pastebin_password'])
|
||||
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 = {}
|
||||
|
||||
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|
|
||||
opts[:gk] = true
|
||||
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|
|
||||
opts[:t] = true
|
||||
end
|
||||
|
@ -43,9 +56,11 @@ elsif opts[:t]
|
|||
elsif opts[:gk]
|
||||
r = pb.scrape_public_pastes
|
||||
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'
|
||||
exit
|
||||
end
|
||||
|
||||
#pp = pb.scrape_public_pastes
|
||||
#puts pb.get_unique_paste_keys(pp)
|
||||
|
|
Loading…
Add table
Reference in a new issue