Class: Irlp::Scraper

Inherits:
Object
  • Object
show all
Defined in:
lib/irlp/scraper.rb

Instance Method Summary collapse

Instance Method Details

#node_status(id) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/irlp/scraper.rb', line 48

def node_status(id)
  node = {}
  
  node_status_url = "#{Irlp::URLS[:node_detail]}&nodeid=#{id}"
  html = html(node_status_url)
  html.css('table tr').each_with_index do |row, i|
    data = row.css('td')[1]
    case i
    when 0
      node[:id] = data.text.to_i
    when 1
      node[:call_sign] = data.text
    when 2
      node[:city] = data.text
    when 3
      node[:province] = data.text
    when 4
      node[:country] = data.text
    when 5
      node[:owner] = data.text
    when 6
      node[:latitude] = data.text
    when 7
      node[:longitude] = data.text
    when 8
      node[:frequency] = data.text
    when 9
      node[:offset] = data.text
    when 10
      node[:tone_squelch] = data.text
    when 11
      node[:avrs_status] = data.text
    when 12
      node[:website] = data.css('a')[0].attr(:href).text if data.css('a').size > 0
    end
  end
  
  node
end

#nodesObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/irlp/scraper.rb', line 24

def nodes
  nodes = []

  html = html(Irlp::URLS[:nodes])
  html.css('table tr').each_with_index do |reflector, i|
    next if i < 1
    cols = reflector.css('td')
    nodes << {
      id: cols[0].text.to_i,
      call_sign: cols[1].text,
      city: cols[2].text,
      province: cols[3].text,
      country: cols[4].text,
      frequency: cols[5].text,
      status: cols[7].text.downcase,
      status_duration: cols[8].text,
      status_link: "#{Irlp::BASE_URL}/index.php?PSTART=11&nodeid=#{cols[0].text}"
    }
  end

  nodes.each { |r| puts "#{r[:id]}: #{r[:call_sign]}"}
  nodes
end

#reflectorsObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/irlp/scraper.rb', line 7

def reflectors
  reflectors = []

  html = html(Irlp::URLS[:reflectors])
  html.css('table tr').each_with_index do |reflector, i|
    next if i < 6
    cols = reflector.css('td')
    reflectors << {
      id: cols[0].text.to_i,
      name: cols[1].text.split.join(' ')
    }
  end

  reflectors.each { |r| puts "#{r[:id]}: #{r[:name]}"}
  reflectors
end