Skip to content

Instantly share code, notes, and snippets.

@ssig33
Created September 21, 2010 04:43
Show Gist options
  • Save ssig33/589211 to your computer and use it in GitHub Desktop.
Save ssig33/589211 to your computer and use it in GitHub Desktop.
class Nyaa
Nyaa_URL = "http://www.nyaatorrents.org/?page=torrents&catid=1&subcat=11"
def self.runner
agent = Mechanize.new
page = agent.get URI.parse Nyaa_URL
page.root.xpath("//tr[@class='tlistrow']").to_ary.each do |a|
url = a.children[3].children.first.attributes.to_hash["href"].to_s
title = a.children[1].children.first.attributes.to_hash["title"].to_s
begin
Entity.find "torrent/#{CGI.escape url}"
rescue
e = Entity.create 'id' => "torrent/#{CGI.escape url}", 'href' => url, 'href' => url, 'title' => title, "created_at" => Time.now.to_i
e.add_to_index "torrent_list", Time.now.to_i
e.add_to_index "torrent_raw_list", Time.now.to_i
end
end
true
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment