Skip to content

Instantly share code, notes, and snippets.

@ssig33
Created November 17, 2010 06:37
Show Gist options
  • Save ssig33/703070 to your computer and use it in GitHub Desktop.
Save ssig33/703070 to your computer and use it in GitHub Desktop.
require "datamapper"
require "mechanize"
require "uri"
DataMapper.setup(:default, "sqlite:///テキトウなディレクトリとファイル名(DataMapper のドキュメント読め)")
class Torrent
include DataMapper::Resource
property :url, Text, :key => true
property :title, Text
end
#Torrent.auto_migrate!
def jibiki
ulrs = ["http://sukebei.nyaatorrents.org/?page=torrents&catid=7&subcat=26"]
ulrs.each{|u|
page = agent.get URI.parse u
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
unless Torrent.get(url)
begin
system "transmissioncli '#{url}' -p ポート -w 'ダウンロードディレクトリ'"
puts "save #{title}:#{url}"
t = Torrent.new
t.url = url
t.title = title
t.save
rescue
end
end
end
}
end
def agent
Mechanize.new
end
while true
jibiki
sleep 300
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment