Advertisement
Guest User

Wallbase Archive Script

a guest
Feb 6th, 2014
19
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #Note: you'll need to make \ruby\img unless you're using the .bat I made
  2. #Images will go to \ruby\img and URLs will go to \ruby\rURLsXXX.txt, where XXX is the starting point
  3.  
  4. require 'net/http'
  5. require 'uri'
  6.  
  7. print "Start point: "
  8. start = gets.to_i
  9.  
  10. print "End point: "
  11. finish = gets.to_i
  12.  
  13. puts
  14.  
  15. i = start
  16. while i <= finish
  17.     #Check wallpaper main page to see if it exists
  18.     url = "http://wallbase.cc/wallpaper/" + i.to_s
  19.     uri = URI.parse(url)
  20.     result = Net::HTTP.start(uri.host, uri.port) { |http| http.get(uri.path) }
  21.  
  22.     if result.code == "404"
  23.         puts "Wallpaper " + i.to_s + " removed"
  24.     elsif result.code == "403"
  25.         puts "Wallpaper " + i.to_s + " hidden"
  26.     else
  27.         #Try to get link from page
  28.         uris = URI.extract(result.body)
  29.         url = (uris.find_all{ |i| i.start_with?("http://wallpapers.wallbase.cc") })[0]
  30.         uri = URI.parse(url)
  31.         result = Net::HTTP.start(uri.host, uri.port) { |http| http.get(uri.path) }
  32.        
  33.         if (result.code != "404" && result.code != "403")
  34.             uri = URI.parse(url).to_s
  35.             File.open(Dir.pwd + "/img/" + File.basename(uri),'wb'){ |f| f.write(result.body) }
  36.             File.open("rURLs" + start.to_s + ".txt", 'a') { |f| f.puts(url) }
  37.             puts "Found: " + url
  38.         else
  39.             puts "Error: bad link " + i.to_s
  40.             File.open("Errors" + start.to_s + ".txt", 'a') { |f| f.puts(i) }
  41.         end
  42.        
  43.     end #end if (wallpaper exists)
  44.    
  45.     i+=1
  46. end
  47.  
  48. puts "All Done!"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement