Advertisement
Guest User

wallbase backup script

a guest
Feb 6th, 2014
9
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rails 1.48 KB | None | 0 0
  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. def make_absolute( href, root )
  8.   URI.parse(root).merge(URI.parse(href)).to_s
  9. end
  10.  
  11. print "Start point: "
  12. start = gets.to_i
  13.  
  14. print "End point: "
  15. finish = gets.to_i
  16.  
  17. puts
  18.  
  19. i = start
  20. while i <= finish
  21.     #Check wallpaper main page to see if it exists
  22.     url = "http://wallbase.cc/wallpaper/" + i.to_s
  23.     uri = URI.parse(url)
  24.     result = Net::HTTP.start(uri.host, uri.port) { |http| http.get(uri.path) }
  25.  
  26.     if result.code == "404"
  27.         puts "Wallpaper " + i.to_s + " removed"
  28.     elsif result.code == "403"
  29.         puts "Wallpaper " + i.to_s + " hidden"
  30.     else
  31.         #Try to get link from page
  32.         uris = URI.extract(result.body)
  33.         url = (uris.find_all{ |i| i.start_with?("http://wallpapers.wallbase.cc") })[0]
  34.         uri = URI.parse(url)
  35.         result = Net::HTTP.start(uri.host, uri.port) { |http| http.get(uri.path) }
  36.        
  37.         if (result.code != "404" && result.code != "403")
  38.             uri = make_absolute(url,"http://wallpapers.wallbase.cc/")
  39.             File.open(Dir.pwd + "/img/" + File.basename(uri),'wb'){ |f| f.write(result.body) }
  40.             File.open("rURLs" + start.to_s + ".txt", 'a') { |f| f.puts(url) }
  41.             puts "Found: " + url
  42.         else
  43.             puts "Error: bad link " + i.to_s
  44.             File.open("Errors" + start.to_s + ".txt", 'a') { |f| f.puts(i) }
  45.         end
  46.        
  47.     end #end if (wallpaper exists)
  48.    
  49.     i+=1
  50. end
  51.  
  52. puts "All Done!"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement