Class: SL::WikipediaSearch

Inherits:
Object
  • Object
show all
Defined in:
lib/searchlink/searches/wikipedia.rb

Class Method Summary collapse

Class Method Details

.search(_, search_terms, link_text) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/searchlink/searches/wikipedia.rb', line 15

def search(_, search_terms, link_text)
  ## Hack to scrape wikipedia result
  body = `/usr/bin/curl -sSL 'https://en.wikipedia.org/wiki/Special:Search?search=#{search_terms.url_encode}&go=Go'`
  return false unless body

  body = body.force_encoding("utf-8") if RUBY_VERSION.to_f > 1.9

  begin
    title = body.match(/"wgTitle":"(.*?)"/)[1]
    url = body.match(/<link rel="canonical" href="(.*?)"/)[1]
  rescue StandardError
    return false
  end

  [url, title, link_text]
end

.settingsObject



6
7
8
9
10
11
12
13
# File 'lib/searchlink/searches/wikipedia.rb', line 6

def settings
  {
    trigger: "wiki",
    searches: [
      ["wiki", "Wikipedia Search"]
    ]
  }
end