edbond (owner)

Revisions

  • 32aad7 edbond Tue Apr 14 10:19:58 -0700 2009
  • a8804d edbond Tue Apr 14 07:48:14 -0700 2009
gist: 95216 Download_button fork
public
Public Clone URL: git://gist.github.com/95216.git
Embed All Files: show embed
torrents.ru updates #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/ruby
#
# fetch new torrents from torrents.ru
# and display them as notifications
 
$KCODE='u'
require 'jcode'
 
require 'rubygems'
require 'net/http'
require 'hpricot'
require 'cgi'
require 'iconv'
require 'sqlite3'
 
def get_firefox_cookies
  home=ENV['HOME']
  profiles_home = File.join(home,".mozilla","firefox")
  profiles = File.read( File.join(profiles_home,"profiles.ini") )
  path = profiles.split(/\[.*\]/).find {|p| p.include?("Default=1")}.match(/Path=(.+)/)[1]
 
  # get into db
  db_file = File.join(profiles_home, path, "cookies.sqlite")
  db = SQLite3::Database.new( db_file )
  cookies = db.execute("SELECT name, value FROM moz_cookies WHERE host=?", ".torrents.ru")
end
 
def get_html
  url = URI.parse('http://torrents.ru/forum/tracker.php')
  http = Net::HTTP.new(url.host, url.port)
  #http.set_debug_output $stderr
 
  cookies = get_firefox_cookies.map {|kv| kv.join('=') }.join(';')
  request = Net::HTTP::Get.new(url.request_uri,'Cookie' => cookies)
  response = http.request(request)
  response.body.strip
end
 
old=[]
i = Iconv.new "utf-8", "windows-1251"
 
loop do
  doc = Hpricot(get_html)
 
  categories = (doc/".f").map {|a| a.inner_text}
  titles = (doc/".tLink b").map {|a| a.inner_text}
  sizes = (doc/".dl-stub").map {|a| a.inner_text}
 
  categories.zip(titles,sizes).each do |row|
    summary = row[0]
    body = "#{row[1]} [#{row[2]}]"
 
    summary = i.iconv(summary)
    body = i.iconv(body)
 
    next if old.include?(body)
    `notify-send -t 5000 '#{summary.gsub(/'/,"\\\\#{$1}")}' '#{body.gsub(/'/,"\\\\#{$1}")}'`
    old << body
    sleep 5
  end
 
  sleep 30
end