Skip to content

Instantly share code, notes, and snippets.

@xeron
Created September 6, 2009 02:04
Show Gist options
  • Save xeron/181604 to your computer and use it in GitHub Desktop.
Save xeron/181604 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'open-uri'
require 'nokogiri'
require 'iconv'
def download(url)
`wget -c --content-disposition http://slil.ru/#{url}`
end
if ARGV.length == 0 || ARGV[0].empty?
puts "Usage: slil.rb id limit --wget query\nDefault limit is 50. If query specified then wget only files named with query included."
else
id = ARGV[0].to_i
if ARGV[1]
limit = id - ARGV[1].to_i
else
limit = id - 50
end
while id > limit and id > 0
data = open("http://slil.ru/#{id}").read
data = Iconv.conv('utf-8','cp1251', data)
doc = Nokogiri::HTML(data)
url = doc.search('a').find { |link| link['href'].include? "#{id}" }
url = url['href'] if url
name = doc.search('p').find { |text| text.content.include? "\302\240\302\240\302\240" }
name = name.content.gsub("\302\240\302\240\302\240", " ").gsub("\r\n", "") if name
puts "http://slil.ru#{url} — #{name}" if url and name
id -= 1
if ARGV[2]=="--wget"
if ARGV[3]
download(url) if name.include?(ARGV[3])
else
download(url)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment