Created
April 3, 2019 00:03
-
-
Save jpsilvashy/0334872f8b8f299925fe2a2d24a6e575 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# == Schema Information | |
# | |
# Table name: proxy_servers | |
# | |
# id :uuid not null, primary key | |
# ip_addr :string | |
# port :string | |
# country :string | |
# last_used_at :datetime | |
# active :boolean | |
# created_at :datetime not null | |
# updated_at :datetime not null | |
# | |
class ProxyServer < ApplicationRecord | |
def self.get_round_robin | |
ProxyServer.where(country: "US").order(last_used_at: :desc).limit(10).sample | |
end | |
# ProxyServer.update_all_proxy_servers | |
def self.update_all_proxy_servers | |
ProxyServer.delete_all | |
params = { | |
email: ENV['PROXY_LIST_EMAIL'], | |
pass: ENV['PROXY_LIST_PASS'], | |
pid: "httppremium", | |
https: "yes" | |
} | |
response = HTTParty.get('http://list.didsoft.com/get', query: params, format: :plain) | |
lines = response.body.split("\n") | |
lines.each do |line| | |
hostname = line.split("#")[0] | |
ip, port = hostname.split(":") | |
ProxyServer.find_or_create_by(ip_addr: ip) do |p| | |
p.port = port | |
p.country = line.split("#")[1] | |
end | |
end | |
end | |
def as_string | |
[self.ip_addr, self.port].join(":") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment