-
Notifications
You must be signed in to change notification settings - Fork 10
/
start.rb
55 lines (41 loc) · 835 Bytes
/
start.rb
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
require 'mechanize'
require_relative './crawler/crawler.rb'
require_relative './model/word.rb'
require 'sinatra'
set :server, 'webrick'
get '/' do
erb :form
end
post '/form' do
@words = params[:words]
@link = params[:link_name]
auth = Authentication.where(:authentication_token=>params[:auth_token])
if auth.nil?
status 403
else
status 200
end
erb :display
end
def app
Sinatra::Application
end
class Server
attr_accessor :crawl
def initialize table
end
def check_table table
return ActiveRecord::Base.connection.table_exists?(:words)
end
def start_crawling link
@thr = Thread.new {
agent = Mechanize.new
page = agent.get(link)
crawl_bot= Crawler.new
crawl_bot.crawl_page(link)
}
end
def crawling_status
return true if @thr.status
end
end