Module: OutriderTools::Crawl

Defined in:
lib/outrider/tools.rb

Class Method Summary collapse

Class Method Details

.site(project, operate) ⇒ Object



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
# File 'lib/outrider/tools.rb', line 24

def self.site project, operate
  
  @log = Logger.new(STDOUT)
  
  recurse = ->() do
    #
    # Pick a from the database to crawl
    unless ProjectData.where( status: 'unscraped', project_id: project[:id] ).exists?
      @log.info "No pages to scrape"
      return false
    end  

    working_page = ProjectData.where( status: 'unscraped', project_id: project[:id]).first
    working_page.status = 'processing'
    working_page.save
    
    @log.info "Scraping #{working_page.url}"
    # Scape it
    data, links = OutriderTools::Scrape::page( working_page.url, operate)

    # save links
    OutriderTools::Link::save_many(links, project, @log )
    
    @log.info "Saving page data for url #{working_page.url}"
    @log.info data[:status]
    working_page.update( data ) unless data.nil?
    
    return true
  end

  crawl = true
  while crawl
    crawl = recurse.call
  end
  
end