# -*- coding: utf-8 -*-

#
# main.rb
#
# Copyright (C) 2009 burgua
#
# lashin.aleksey@gmail.com
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#

require 'rubygems'
require 'plasma_applet'
require 'curb'
require 'md5'
require 'iconv'

module Vkontakte
  class Main < PlasmaScripting::Applet
    def initialize parent
      super parent
    end

    def init
      self.has_configuration_interface = false
      self.aspect_ratio_mode = Plasma::Square
      self.background_hints = Plasma::Applet.DefaultBackground
      layout = Qt::GraphicsLinearLayout.new Qt::Horizontal, self
      label = Plasma::Label.new self
      layout.add_item label
      self.layout = layout
      resize 600, 1200
      label.text = "Wait a bit..."
      Thread.new { while true; label.text=getdata; sleep(30);  end }
    end

    def trymatch (str,regex)
    	if (str.match(/#{regex}/u) == nil)
        return '0'
      end
      str.match(/#{regex}/u)[2]
    end

    def filter (data, label, tool)
      str = 'href=\''+tool+'.php([A-Za-zА-Яа-я=\?\'\s\d&>]*)\(<b>(.+)<\/b>'
      rez = trymatch(data,str)
      if (rez=='0')
        return ''
      end
      '<tr><td>' + label +  "</td><td><b>"+ rez + '</b></td></tr>'
    end

    def getdata
      # get data from xml-file
      user = {'mid' => '******', 'email' => '********', 'pass' => MD5.md5('*********')}
      # getted
      curl = Curl::Easy.new('http://vkontakte.ru/id872527')
      curl.headers = {"User-Agent" => "Mozilla/5.0 (X11; U; Linux i686; ru; rv:1.9.0.4) Gecko/2008112309 Iceweasel/3.0.4 (Debian-3.0.4-1)",
                "Cookie" => "remixlang=0; remixchk=5; remixmid=#{user['mid']}; remixemail=#{user['email']}; remixpass=#{user['pass']}; remixautobookmark=8",
                "Referer" => "http://vkontakte.ru/"}
      curl.follow_location = true
      curl.perform
      #return '0'
      body = curl.unescape curl.body_str
      coder = Iconv.new("UTF-8","WINDOWS-1251")
      body = coder.iconv(body)
      result = '<table>'
        result = result + filter(body,'Friends','friend')
        result = result + filter(body,'Photos','photos')
        result = result + filter(body,'Videos','video')
        result = result + filter(body,'Messages','mail')
        result = result + filter(body,'Notes','notes')
        result = result + filter(body,'Groups','groups')
        result = result + filter(body,'Events','events')
        result = result + filter(body,'Matches','matches')
        result = result + filter(body,'Opinions','opinions')
        result = result + filter(body,'Questions','questions')
        result = result + filter(body,'Opinions','opinions')
      result = result + '</table>'
    end

  end

end

Colored with dumpz.org

Colored with dumpz.org