lib/proxy_manager/main.rb in proxy_manager-0.0.8 vs lib/proxy_manager/main.rb in proxy_manager-0.0.9
- old
+ new
@@ -14,10 +14,11 @@
end
@list_file, @bad_list_file = proxies, bad_proxies
load_list_from_file(proxies)
+ load_bad_list_from_file(bad_proxies)
end
end
def connectable?(proxy)
proxy = proxy.chomp.split(':') if proxy.is_a? String
@@ -26,16 +27,17 @@
def get(count = 1)
raise 'List is empty' if @list.empty?
items = []
+ new_list = @list.clone
@list.each_with_index do |proxy, key|
- @list.delete_at(key)
+ new_list.shift
if connectable? proxy
- @list << proxy
+ new_list << proxy
if count == 1
items = proxy
break
else
@@ -45,10 +47,12 @@
else
@bad_list << proxy
end
end
+ @list = new_list
+
raise 'There are no available proxy' if items.empty?
if @list_file && @bad_list_file
File.open(@list_file, "w+") do |f|
source = ''
@@ -85,9 +89,18 @@
def load_list_from_file(proxies)
File.open(proxies, "r").each do |line|
line = line.chomp.split(':')
if line[0].is_a? String and line[1].is_a? String
@list << [line[0], line[1].to_i]
+ end
+ end
+ end
+
+ def load_bad_list_from_file(bad_proxies)
+ File.open(bad_proxies, "r").each do |line|
+ line = line.chomp.split(':')
+ if line[0].is_a? String and line[1].is_a? String
+ @bad_list << [line[0], line[1].to_i]
end
end
end
end
end