#!/usr/bin/env ruby require 'optparse' require 'proxy_fetcher' options = { filters: {}, validate: true, json: false } OptionParser.new do |opts| opts.banner = 'Usage: proxy_fetcher [OPTIONS]' opts.on('-h', '--help', '# Show this help message and quit') do puts opts exit(0) end opts.on('-p', '--providers=NAME1,NAME2', Array, '# Use specific proxy providers') do |values| options[:providers] = values end opts.on('-n', '--no-validate', '# Dump all the proxies without validation') do options[:validate] = false end opts.on('-f', '--filters={}', String, '# Filters for proxy provider in JSON format') do |filters| require 'json' options[:filters] = JSON.parse(filters) end opts.on('-t', '--timeout=SECONDS', Integer, '# Connection timeout in seconds') do |value| options[:timeout] = value end opts.on('-j', '--json', '# Dump proxies to the JSON format') do options[:json] = true end end.parse! ProxyFetcher.config.providers = options[:providers] if options[:providers] ProxyFetcher.config.connection_timeout = options[:timeout] if options[:timeout] manager = ProxyFetcher::Manager.new(filters: options[:filters]) manager.validate! if options[:validate] if options[:json] require 'json' puts JSON.generate(proxies: manager.raw_proxies) else puts manager.raw_proxies end