View difference between Paste ID: Gz8buhDs and ybGyPetc
SHOW: | | - or go back to the newest paste.
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 )
7+
8-
  URI.parse(root).merge(URI.parse(href)).to_s
8+
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-
			uri = make_absolute(url,"http://wallpapers.wallbase.cc/")
38+
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!"