Class: RHACK::VK
Defined Under Namespace
Classes: NotFoundError
Constant Summary collapse
- URI =
{ :people => "http://vkontakte.ru/gsearch.php?from=people&ajax=1", :login => "http://vkontakte.ru/index.php", :id => "http://vkontakte.ru%s" }
- DefaultParams =
- @@reloadable =
ReloadablePage { if !@title and !@hash L << self L << @doc end if @hash == false or @hash.nil? && (!@title or @title["Ошибка"]) L.info "@title caller.size", binding sleep 2 end }
Instance Attribute Summary collapse
-
#links ⇒ Object
readonly
Returns the value of attribute links.
-
#open_links ⇒ Object
readonly
Returns the value of attribute open_links.
Class Method Summary collapse
Instance Method Summary collapse
- #get_links(h, pagenum, &block) ⇒ Object
- #get_page(id, q = nil) ⇒ Object
- #get_pages(q = nil) ⇒ Object
- #get_people(q, *opts) ⇒ Object
-
#initialize(frame = nil) ⇒ VK
constructor
A new instance of VK.
- #login(params = {'email'=>'[email protected]', 'pass'=>'Riddick2', 'expire'=>nil}) ⇒ Object
- #people(q, *args, &block) ⇒ Object
Constructor Details
#initialize(frame = nil) ⇒ VK
Returns a new instance of VK.
269 270 271 272 273 274 |
# File 'lib/rhack/clients/examples.rb', line 269 def initialize frame=nil super :people, frame, {:cp => true, :relvl => 5, :eval => false}, 5 @links = [] @open_links = [] login end |
Instance Attribute Details
#links ⇒ Object (readonly)
Returns the value of attribute links.
240 241 242 |
# File 'lib/rhack/clients/examples.rb', line 240 def links @links end |
#open_links ⇒ Object (readonly)
Returns the value of attribute open_links.
240 241 242 |
# File 'lib/rhack/clients/examples.rb', line 240 def open_links @open_links end |
Class Method Details
.com ⇒ Object
265 |
# File 'lib/rhack/clients/examples.rb', line 265 def self.com; new end |
Instance Method Details
#get_links(h, pagenum, &block) ⇒ Object
282 283 284 285 286 287 288 |
# File 'lib/rhack/clients/examples.rb', line 282 def get_links h, pagenum, &block @f.run(h.merge('offset' => pagenum*20), URI[:people], :proc_result=>block, :result=>@@reloadable, :json => true) {|page| ls = Page(page.hash.rows).get_links('.image/a') @links.concat ls ls } end |
#get_page(id, q = nil) ⇒ Object
325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 |
# File 'lib/rhack/clients/examples.rb', line 325 def get_page id, q=nil q = q ? q.ci.to_re : // unless q.is Regexp id_num = id[/\d+/].to_i @f.get(id, :result=>@@reloadable) {|p| data = p.find('.profileTable//.dataWrap').to_a.b if data L.debug "!p.at('.basicInfo//.alertmsg') data.contents.join('')[/(\\d\\s*){6,}/] data.contents.join('')[q]", binding end if data = p.find('.profileTable//.dataWrap').b and contents = data.to_a.contents.join.b and contents[q] digits = contents[/(\d *){6,9}/] bot = (digits and digits[/^\d{7}$/] and id_num.between 852e5, 893e5) if !bot and !p.at('.basicInfo//.alertmsg') || digits L << "added vk.com#{id}" @open_links << id elsif bot L << "bot #{id_num} detected" else tick! end else tick! end } end |
#get_pages(q = nil) ⇒ Object
321 322 323 |
# File 'lib/rhack/clients/examples.rb', line 321 def get_pages q=nil @links.uniq.each {|id| get_page id, q; sleep 1.5} end |
#get_people(q, *opts) ⇒ Object
314 315 316 317 318 319 |
# File 'lib/rhack/clients/examples.rb', line 314 def get_people q, *opts @links = [] @open_links = [] people q, *opts get_pages q end |
#login(params = {'email'=>'[email protected]', 'pass'=>'Riddick2', 'expire'=>nil}) ⇒ Object
276 277 278 279 280 |
# File 'lib/rhack/clients/examples.rb', line 276 def login params={'email'=>'[email protected]', 'pass'=>'Riddick2', 'expire'=>nil} super {|login_page| login_page.submit('form', @f, params).submit('form', @f, {}) } end |
#people(q, *args, &block) ⇒ Object
290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 |
# File 'lib/rhack/clients/examples.rb', line 290 def people(q, *args, &block) age, opts = args.get_opts [17..23] h = DefaultParams.merge('c[q]' => q) h.merge! Hash[opts.map {|k,v| ["c[#{k}]", v]}] h['c[age_from]'], h['c[age_to]'] = age.first, age.last @f.run(h, URI[:people], :proc_result => block, :json => true) {|page| # ответом может быть невнятное требование залогиниться sum = page.hash.summary.sub(/<span.+>/, '') puts sum found = sum[/\d+/] if !found L.warn sum else @links.concat Page(page.hash.rows).get_links('.image/a') max_page = [50, (found.to_f/20).ceil].min (1...max_page).each {|_| sleep 0.5 get_links h, _, &block } end } end |